dialog_edit_label.cpp 4.54 KB
Newer Older
plyatov's avatar
plyatov committed
1
/////////////////////////////////////////////////////////////////////////////
dickelbeck's avatar
dickelbeck committed
2

plyatov's avatar
plyatov committed
3 4
// Name:        dialog_edit_label.cpp
// Author:      jean-pierre Charras
5
// Modified by:
6 7
// Created:     18/12/2008 15:46:26
// Licence: GPL
plyatov's avatar
plyatov committed
8 9
/////////////////////////////////////////////////////////////////////////////

10 11
#include "fctsys.h"
#include "wx/valgen.h"
plyatov's avatar
plyatov committed
12

13
#include "common.h"
14
#include "class_drawpanel.h"
15 16
#include "program.h"
#include "general.h"
plyatov's avatar
plyatov committed
17 18
#include "dialog_edit_label.h"

19 20 21 22

int DialogLabelEditor::ShowModally(  WinEDA_SchematicFrame* parent, SCH_TEXT * CurrentText )
{
    int ret;
23

24
    DialogLabelEditor* dialog = new DialogLabelEditor( parent, CurrentText );
25 26 27 28 29 30 31 32 33 34 35 36

    // doing any post construction resizing is better done here than in
    // OnInitDialog() since it tends to flash/redraw the dialog less.
    dialog->init();

    ret = dialog->ShowModal();
    dialog->Destroy();
    return ret;
}



37 38
DialogLabelEditor::DialogLabelEditor( WinEDA_SchematicFrame* parent, SCH_TEXT* CurrentText ) :
    DialogLabelEditor_Base( parent )
plyatov's avatar
plyatov committed
39
{
40
    m_Parent = parent;
dickelbeck's avatar
dickelbeck committed
41
    m_CurrentText = CurrentText;
42
    init();
plyatov's avatar
plyatov committed
43 44
}

dickelbeck's avatar
dickelbeck committed
45

46
void DialogLabelEditor::init()
plyatov's avatar
plyatov committed
47
{
dickelbeck's avatar
dickelbeck committed
48
    wxString msg;
49
    bool multine = false;
charras's avatar
charras committed
50

51 52 53 54
    if( m_CurrentText->m_MultilineAllowed )
    {
        m_TextLabel = m_textCtrlMultiline;
        m_TextLabelSingleline->Show(false);
55
        multine = true;
56 57 58 59 60 61
    }
    else
    {
        m_TextLabel = m_TextLabelSingleline;
       m_textCtrlMultiline->Show(false);
    }
62

dickelbeck's avatar
dickelbeck committed
63
    m_TextLabel->SetValue( m_CurrentText->m_Text );
64
    m_TextLabel->SetFocus();
65

66 67
    switch( m_CurrentText->Type() )
    {
dickelbeck's avatar
dickelbeck committed
68 69 70 71 72 73
    case TYPE_SCH_GLOBALLABEL:
        SetTitle( _( "Global Label Properties" ) );
        break;

    case TYPE_SCH_HIERLABEL:
        SetTitle( _( "Hierarchal Label Properties" ) );
charras's avatar
charras committed
74
        m_TextShape->SetLabel( _("Hlabel Shape") );
dickelbeck's avatar
dickelbeck committed
75
        break;
76

dickelbeck's avatar
dickelbeck committed
77 78 79 80 81 82
    case TYPE_SCH_LABEL:
        SetTitle( _( "Label Properties" ) );
        break;

    default:
        SetTitle( _( "Text Properties" ) );
83
      	m_TextLabel->Disconnect(wxEVT_COMMAND_TEXT_ENTER , wxCommandEventHandler ( DialogLabelEditor::onEnterKey ), NULL, this);
dickelbeck's avatar
dickelbeck committed
84 85
        break;
    }
86

dickelbeck's avatar
dickelbeck committed
87
    unsigned MINTEXTWIDTH  = 30;    // M's are big characters, a few establish a lot of width
88

dickelbeck's avatar
dickelbeck committed
89 90 91 92 93
    if( m_CurrentText->m_Text.Length() < MINTEXTWIDTH )
    {
        wxString textWidth;
        textWidth.Append( 'M', MINTEXTWIDTH );
        EnsureTextCtrlWidth( m_TextLabel, &textWidth );
94
    }
95
    else if ( ! multine )
dickelbeck's avatar
dickelbeck committed
96
        EnsureTextCtrlWidth( m_TextLabel );
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    else
    {
        // calculate the lenght of the biggest line
        // we cannot use the lenght of the entire text that has no meaning
        int max_len = 0;
        int curr_len = 0;
        int imax = m_CurrentText->m_Text.Len();
        for( int count = 0; count < imax; count++ )
        {
            if( m_CurrentText->m_Text[count] == '\n' ||
                 m_CurrentText->m_Text[count] == '\r' ) // new line
                {
                    curr_len = 0;
                }
            else
            {
                curr_len++;
                if ( max_len < curr_len )
                    max_len = curr_len;
            }
        }
        wxString textWidth;
        textWidth.Append( 'M', max_len );
        EnsureTextCtrlWidth( m_TextLabel, &textWidth );
    }
dickelbeck's avatar
dickelbeck committed
122 123

    // Set validators
124
    m_TextOrient->SetSelection( m_CurrentText->GetSchematicTextOrientation() );
dickelbeck's avatar
dickelbeck committed
125
    m_TextShape->SetSelection( m_CurrentText->m_Shape );
126

127
    int style = 0;
dickelbeck's avatar
dickelbeck committed
128
    if( m_CurrentText->m_Italic )
129
        style = 1;
charras's avatar
charras committed
130
    if( m_CurrentText->m_Bold )
131
        style += 2;
dickelbeck's avatar
dickelbeck committed
132 133

    m_TextStyle->SetSelection( style );
134 135

    msg = m_SizeTitle->GetLabel() + ReturnUnitSymbol();
dickelbeck's avatar
dickelbeck committed
136
    m_SizeTitle->SetLabel( msg );
137

dickelbeck's avatar
dickelbeck committed
138 139
    msg = ReturnStringFromValue( g_UnitMetric, m_CurrentText->m_Size.x, m_Parent->m_InternalUnits );
    m_TextSize->SetValue( msg );
charras's avatar
charras committed
140

dickelbeck's avatar
dickelbeck committed
141 142 143 144 145
    if( m_CurrentText->Type() != TYPE_SCH_GLOBALLABEL
     && m_CurrentText->Type() != TYPE_SCH_HIERLABEL )
    {
        m_TextShape->Show( false );
    }
plyatov's avatar
plyatov committed
146

dickelbeck's avatar
dickelbeck committed
147
    if( GetSizer() )
148
    {
dickelbeck's avatar
dickelbeck committed
149
        GetSizer()->SetSizeHints( this );
150
    }
plyatov's avatar
plyatov committed
151 152
}

153 154 155 156 157 158 159 160
/*!
 * wxTE_PROCESS_ENTER  event handler for m_TextLabel
 */

void DialogLabelEditor::onEnterKey( wxCommandEvent& event )
{
    TextPropertiesAccept( event );
}
161

plyatov's avatar
plyatov committed
162 163 164 165
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
 */

166
void DialogLabelEditor::OnButtonOKClick( wxCommandEvent& event )
plyatov's avatar
plyatov committed
167
{
dickelbeck's avatar
dickelbeck committed
168
    TextPropertiesAccept( event );
charras's avatar
charras committed
169
    EndModal( wxID_OK );
plyatov's avatar
plyatov committed
170 171
}

dickelbeck's avatar
dickelbeck committed
172

plyatov's avatar
plyatov committed
173
/*!
174
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
plyatov's avatar
plyatov committed
175 176
 */

177
void DialogLabelEditor::OnButtonCANCEL_Click( wxCommandEvent& event )
plyatov's avatar
plyatov committed
178
{
179
    m_Parent->DrawPanel->MouseToCursorSchema();
charras's avatar
charras committed
180
    EndModal( wxID_CANCEL );
plyatov's avatar
plyatov committed
181
}
182