~ubuntu-branches/ubuntu/wily/ginkgocadx/wily-proposed

« back to all changes in this revision

Viewing changes to src/cadxcore/widgets/gui/selecciontexto.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-bql5wep49c7hg91t
Tags: upstream-2.4.1.1
ImportĀ upstreamĀ versionĀ 2.4.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *  $Id: selecciontexto.cpp 3526 2011-03-16 19:56:19Z carlos $
 
4
 *  Ginkgo CADx Project
 
5
 *
 
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
 *  http://ginkgo-cadx.com
 
8
 *
 
9
 *  This file is licensed under LGPL v3 license.
 
10
 *  See License.txt for details
 
11
 *
 
12
 *
 
13
 */
 
14
#include <cmath>
 
15
#include <wx/icon.h>
 
16
#include "selecciontexto.h"
 
17
#include <api/iwidgetsmanager.h>
 
18
#include <resources/ginkgoresourcemanager.h>
 
19
#include <wx/xml/xml.h>
 
20
 
 
21
GNC::GCS::Widgets::Dialogos::SeleccionTexto::SeleccionTexto(wxWindow* parent, TWidget* pWidget, TManager* pManager) : SeleccionTextoBase(parent)
 
22
{
 
23
        wxIcon icono;
 
24
        icono.CopyFromBitmap(GinkgoResourcesManager::IconosMenus::GetIcoEditar());
 
25
        this->SetIcon(icono);
 
26
 
 
27
        m_pWidget = pWidget;
 
28
        m_pManager = pManager;
 
29
        m_pControlTexto->SetValue(wxString::FromUTF8(m_pWidget->m_Texto.c_str()));
 
30
        m_pControlTexto->SetSelection(-1,-1);
 
31
        m_pColorPicker->SetColour( wxColour( (unsigned char) (pWidget->m_Color.B8()), (unsigned char) (pWidget->m_Color.G8()), (unsigned char) (pWidget->m_Color.R8()) ) );
 
32
        IniciarColores();
 
33
 
 
34
}
 
35
 
 
36
GNC::GCS::Widgets::Dialogos::SeleccionTexto::~SeleccionTexto()
 
37
{
 
38
        if (m_pWidget != NULL && m_pWidget->m_pWidgetSeleccion == this) {
 
39
                m_pWidget->m_pWidgetSeleccion= NULL;
 
40
        }
 
41
}
 
42
 
 
43
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnClickEnMenu(wxCommandEvent& /*event*/){
 
44
        Center();
 
45
        ShowModal();
 
46
}
 
47
 
 
48
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnDialogoKeyDown( wxKeyEvent& event )
 
49
{
 
50
        if (event.GetKeyCode() == WXK_ESCAPE) {
 
51
                Close();
 
52
        }
 
53
        else if (event.GetKeyCode() == WXK_RETURN) {
 
54
                Actualizar();
 
55
                Close();
 
56
        }
 
57
        else {
 
58
                event.Skip();
 
59
        }
 
60
}
 
61
 
 
62
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnControlTextoKeyDown( wxKeyEvent& event )
 
63
{
 
64
        if (event.GetKeyCode() == WXK_ESCAPE) {
 
65
                Close();
 
66
        }
 
67
        else {
 
68
                event.Skip();
 
69
        }
 
70
}
 
71
 
 
72
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnControlTextoTextoActualizado( wxCommandEvent& event )
 
73
{
 
74
        event.Skip();
 
75
}
 
76
 
 
77
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnBotonCancelarClick( wxCommandEvent& /*event*/ )
 
78
{
 
79
        Close();
 
80
}
 
81
 
 
82
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnBotonAceptarClick( wxCommandEvent& /*event*/ )
 
83
{
 
84
        Actualizar();
 
85
        Close();
 
86
}
 
87
 
 
88
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnColorCambiado(wxColourPickerEvent& /*event*/)
 
89
{
 
90
        Actualizar(false);
 
91
}
 
92
 
 
93
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::OnActivar(wxActivateEvent &/*event*/)
 
94
{
 
95
        m_pControlTexto->SetFocus();
 
96
}
 
97
 
 
98
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::IniciarColores()
 
99
{
 
100
        const GNC::GCS::Widgets::Color& colorWidget = m_pWidget->GetColor();
 
101
        const GNC::GCS::Widgets::Color colorFondo = colorWidget.Inverso();
 
102
 
 
103
        wxColour wColorFondo (colorFondo.R8(), colorFondo.G8(), colorFondo.B8());
 
104
        wxColour wColorTexto (colorWidget.B8(), colorWidget.G8(), colorWidget.R8());
 
105
 
 
106
        m_pColorPicker->SetColour(wColorTexto);
 
107
 
 
108
        m_pControlTexto->SetForegroundColour(wColorTexto);
 
109
        m_pControlTexto->SetBackgroundColour(wColorFondo);
 
110
}
 
111
 
 
112
void GNC::GCS::Widgets::Dialogos::SeleccionTexto::Actualizar(bool actualizarWidget)
 
113
{
 
114
        wxColour wColorFondo;
 
115
        wxColour wColorTexto = m_pColorPicker->GetColour();
 
116
 
 
117
        GNC::GCS::Widgets::Color colorTexto(wColorTexto.Blue(), wColorTexto.Green(), wColorTexto.Red());
 
118
        GNC::GCS::Widgets::Color ctmp = GNC::GCS::Widgets::Color(colorTexto).Invertir();
 
119
 
 
120
        wColorFondo.Set(ctmp.B8(), ctmp.G8(), ctmp.R8());
 
121
 
 
122
        m_pControlTexto->SetForegroundColour(wColorTexto);
 
123
        m_pControlTexto->SetBackgroundColour(wColorFondo);
 
124
        m_pControlTexto->Refresh();
 
125
 
 
126
        if (actualizarWidget) {
 
127
 
 
128
                bool modifica = false;
 
129
 
 
130
                if (colorTexto != m_pWidget->GetColor()) {
 
131
                        m_pWidget->SetColor(colorTexto);
 
132
                        modifica = true;
 
133
                }
 
134
 
 
135
                std::string textoControl(m_pControlTexto->GetValue().ToUTF8());
 
136
 
 
137
                if (m_pWidget->GetTexto() != textoControl) {
 
138
                        m_pWidget->SetTexto(textoControl);
 
139
                        modifica = true;
 
140
                }
 
141
 
 
142
                if (modifica) {
 
143
                        m_pWidget->Invalidar();
 
144
                        m_pWidget->PropagarModificacion();
 
145
                }
 
146
        }
 
147
 
 
148
}
 
149