cvstruct.h 6.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file cvstruct.h
 */
plyatov's avatar
plyatov committed
27 28 29 30

#ifndef CVSTRUCT_H
#define CVSTRUCT_H

31
#include <wx/listctrl.h>
32

plyatov's avatar
plyatov committed
33 34

/*  Forward declarations of all top-level window classes. */
35
class CVPCB_MAINFRAME;
36
class COMPONENT;
37
class FOOTPRINT_LIST;
38

plyatov's avatar
plyatov committed
39

40 41 42 43
/*********************************************************************/
/* ListBox (base class) to display lists of components or footprints */
/*********************************************************************/
class ITEMS_LISTBOX_BASE : public wxListView
plyatov's avatar
plyatov committed
44 45
{
public:
46
    ITEMS_LISTBOX_BASE( CVPCB_MAINFRAME* aParent, wxWindowID aId,
47
                        const wxPoint& aLocation, const wxSize& aSize,
48
                        long aStyle = wxLC_SINGLE_SEL );
plyatov's avatar
plyatov committed
49

50
    ~ITEMS_LISTBOX_BASE();
plyatov's avatar
plyatov committed
51

52 53
    int                      GetSelection();
    void                     OnSize( wxSizeEvent& event );
54

55
    virtual CVPCB_MAINFRAME* GetParent() const;
plyatov's avatar
plyatov committed
56 57
};

58

59 60 61 62
/******************************************/
/* ListBox showing the list of footprints */
/******************************************/
class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
plyatov's avatar
plyatov committed
63 64
{
private:
65
    wxArrayString  m_footprintList;
66

plyatov's avatar
plyatov committed
67
public:
68 69 70 71 72 73 74 75
    enum FP_FILTER_T
    {
        UNFILTERED   = 0,
        BY_COMPONENT = 0x0001,
        BY_PIN_COUNT = 0x0002,
        BY_LIBRARY   = 0x0004,
    };

76
    FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
77
                        const wxPoint& loc, const wxSize& size );
78 79 80
    ~FOOTPRINTS_LISTBOX();

    int      GetCount();
81
    void     SetSelection( int index, bool State = true );
82 83
    void     SetString( unsigned linecount, const wxString& text );
    void     AppendLine( const wxString& text );
84 85

    /**
86 87 88 89 90 91 92 93 94
     * Function SetFootprints
     * populates the wxListCtrl with the footprints from \a aList that meet the filter
     * criteria defined by \a aFilterType.
     *
     * @param aList is a #FOOTPRINT_LIST item containing the footprints.
     * @param aLibName is wxString containing the name of the selected library.  Can be
     *                 wxEmptyString.
     * @param aComponent is the #COMPONENT used by the filtering criteria.  Can be NULL.
     * @param aFilterType defines the criteria to filter \a aList.
95
     */
96 97
    void     SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
                            COMPONENT* aComponent, int aFilterType );
98 99

    wxString GetSelectedFootprint();
100 101 102 103 104 105

    /**
     * Function OnGetItemText
     * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
     * because real data is not handled by ITEMS_LISTBOX_BASE
     */
106 107 108 109 110
    wxString OnGetItemText( long item, long column ) const;

    // Events functions:
    void     OnLeftClick( wxListEvent& event );
    void     OnLeftDClick( wxListEvent& event );
111
    void     OnChar( wxKeyEvent& event );
112

113 114 115
    DECLARE_EVENT_TABLE()
};

116

117 118 119 120 121
/******************************************/
/* ListBox showing the list of library */
/******************************************/
class LIBRARY_LISTBOX : public ITEMS_LISTBOX_BASE
{
122
    wxArrayString  m_libraryList;
123 124 125

public:
    LIBRARY_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
126
                     const wxPoint& loc, const wxSize& size );
127 128 129
    ~LIBRARY_LISTBOX();

    int      GetCount();
130
    void     SetSelection( int index, bool State = true );
131 132
    void     SetString( unsigned linecount, const wxString& text );
    void     AppendLine( const wxString& text );
133
    void     SetLibraryList( const wxArrayString& aList );
134 135 136 137 138 139

    wxString GetSelectedLibrary();
    wxString OnGetItemText( long item, long column ) const;

    // Events functions:
    void     OnLeftClick( wxListEvent& event );
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

    void     OnSelectLibrary( wxListEvent& event );

    /**
     * Function OnChar
     * called on a key pressed
     * Call default handler for some special keys,
     * and for "ascii" keys, select the first footprint
     * that the name starts by the letter.
     * This is the defaut behaviour of a listbox, but because we use
     * virtual lists, the listbox does not know anything to what is displayed,
     * we must handle this behaviour here.
     * Furthermore the footprint name is not at the beginning of
     * displayed lines (the first word is the line number)
     */
155
    void     OnChar( wxKeyEvent& event );
156 157

    DECLARE_EVENT_TABLE()
plyatov's avatar
plyatov committed
158 159
};

160

161 162 163 164
/****************************************************/
/* ListBox showing the list of schematic components */
/****************************************************/
class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
plyatov's avatar
plyatov committed
165 166
{
public:
167
    wxArrayString      m_ComponentList;
168
    CVPCB_MAINFRAME*   m_Parent;
plyatov's avatar
plyatov committed
169 170 171

public:

172
    COMPONENTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
173
                        const wxPoint& loc, const wxSize& size );
plyatov's avatar
plyatov committed
174

175
    ~COMPONENTS_LISTBOX();
176

177 178
    void     Clear();
    int      GetCount();
179 180 181 182 183 184

    /**
     * Function OnGetItemText
     * this overloaded function MUST be provided for the wxLC_VIRTUAL mode
     * because real data is not handled by ITEMS_LISTBOX_BASE
     */
185
    wxString OnGetItemText( long item, long column ) const;
186 187 188 189

    /*
     * Enable or disable an item
     */
190
    void     SetSelection( int index, bool State = true );
191 192 193 194
    void     SetString( unsigned linecount, const wxString& text );
    void     AppendLine( const wxString& text );

    // Events functions:
195 196 197 198 199 200 201 202 203 204 205 206 207

    /**
     * Function OnChar
     * called on a key pressed
     * Call default handler for some special keys,
     * and for "ascii" keys, select the first component
     * that the name starts by the letter.
     * This is the default behavior of a listbox, but because we use
     * virtual lists, the listbox does not know anything to what is displayed,
     * we must handle this behavior here.
     * Furthermore the reference of components is not at the beginning of
     * displayed lines (the first word is the line number)
     */
208
    void     OnChar( wxKeyEvent& event );
209

210 211
    void     OnSelectComponent( wxListEvent& event );

212
    DECLARE_EVENT_TABLE()
plyatov's avatar
plyatov committed
213 214 215
};


216
#endif  //#ifndef CVSTRUCT_H