File: destinations_wizardpage.cpp

package info (click to toggle)
plucker 1.8-34
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,340 kB
  • sloc: ansic: 47,691; cpp: 42,310; python: 17,043; makefile: 1,521; perl: 1,492; pascal: 1,123; sh: 474; sed: 64; java: 13; csh: 6
file content (206 lines) | stat: -rw-r--r-- 9,038 bytes parent folder | download | duplicates (4)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//----------------------------------------------------------------------------------------
// Name:        destinations_wizardpage.cpp
// Purpose:     A wizardpage of destinations to install output to
// Author:      Robert O'Connor
// Modified by:
// Created:     2001/10/20
// Copyright:   (c) Robert O'Connor ( rob@medicalmnemonics.com )
// Licence:     GPL
// RCS-ID:      $Id: destinations_wizardpage.cpp,v 1.8 2004/01/04 00:57:49 robertoconnor Exp $
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
// GCC implementation
//----------------------------------------------------------------------------------------

#if defined(__GNUG__) && ! defined(__APPLE__)
    #pragma implementation "destinations_wizardpage.h"
#endif

//----------------------------------------------------------------------------------------
// Setup information
//----------------------------------------------------------------------------------------

#include "setup.h"

//----------------------------------------------------------------------------------------
// Begin feature removal condition
//----------------------------------------------------------------------------------------

#if ( setupUSE_WIZARDS )

//----------------------------------------------------------------------------------------
// Standard wxWindows headers
//----------------------------------------------------------------------------------------

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// For all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWindows headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

//----------------------------------------------------------------------------------------
// Header of this .cpp file
//----------------------------------------------------------------------------------------

#include "destinations_wizardpage.h"

//----------------------------------------------------------------------------------------
// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers
//----------------------------------------------------------------------------------------

#include "wx/sizer.h"

// ---------------------------------------------------------------------------------------

#include "configuration.h"
#include "image_list.h"
#include "utils_string.h"
#include "handheld_dest_wrappers.h"

//----------------------------------------------------------------------------------------
// Event table: connect the events to the handler functions to process them
//----------------------------------------------------------------------------------------

BEGIN_EVENT_TABLE( destinations_wizardpage, wxWizardPageSimple )
    EVT_WIZARD_PAGE_CHANGING( -1, destinations_wizardpage::on_wizardpage_changing )
END_EVENT_TABLE()

//----------------------------------------------------------------------------------------
// Public methods
//----------------------------------------------------------------------------------------

destinations_wizardpage::destinations_wizardpage
    ( 
    wxWizard *parent,
    const wxString& handheld_destinations_label, 
    const wxString& directory_destinations_label,
    const wxString& channel_section,
    wxBitmap bitmap
    )
    : wxWizardPageSimple( parent )
{
    wxLogDebug( "Entering destinations_wizardpage constructor" );
  
    // To set a custom bitmap in a derived wxWizardPageSimple, you just have to 
    // set the wxWizardPageSimple m_bitmap member in the derived constructor.
    // ( see wx examples ). .
    m_bitmap = bitmap;
    
    // Create the handheldlistctrl    
    m_handheld_install_ctrl = new wxHandheldInstallCtrl( this, -1,
                                            handheld_destinations_label,
                                            directory_destinations_label);                                                            
    wxLogDebug( "Created a new wxHandheldInstallCtrl" );                                
    
    // Make a new flexgrid sizer ( format # of rows, # of columns, then hor/vert gaps)
    wxFlexGridSizer *root_flexgridsizer = new wxFlexGridSizer( 1, 0, 0 );
    // Set the growable columns and rows
    root_flexgridsizer->AddGrowableCol( 0 );
    root_flexgridsizer->AddGrowableRow( 0 );

    // Add handheldctrl to sizer.
    root_flexgridsizer->Add( m_handheld_install_ctrl, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 0 );

    // Now that everything is added into the flexgrid sizer, send some commands to 
    // tell it calculate all the control sizes nicely to fill up the available space.
    SetAutoLayout( TRUE );
    SetSizer( root_flexgridsizer );
    root_flexgridsizer->Fit( this );
    root_flexgridsizer->SetSizeHints( this );     
  
    // Set up the listctrl icons for the wxHandheldInstallerCtrl
    m_handheld_install_ctrl->SetImageList( image_list::get() );
    m_handheld_install_ctrl->SetUsersImageListImageId( plkrSMALL_IMAGE_LIST_ID_CHANNEL_DIALOG_DESTINATION_TAB_USERS_LISTCTRL );
    m_handheld_install_ctrl->SetDirectoriesImageListImageId( plkrSMALL_IMAGE_LIST_ID_CHANNEL_DIALOG_DESTINATION_TAB_DIRECTORIES_LISTCTRL );
    
    
    // Initialize the values for the control to our passed section:
    handheld_dest_array_type handheld_dest_array;
    handheld_dest_wrappers::read_handheld_dest_array_from_configuration( channel_section,
                                                                       &handheld_dest_array );
    m_handheld_install_ctrl->InsertUserDestinations( handheld_dest_array );

    wxArrayString sync_directories_array;
    wxString sync_directories_string = the_configuration->Read( "/" + channel_section +
                                                                "/copy_to_dir", "" );
    // Converts the read string to an array of integers.
    utils_string::string_to_arraystring( sync_directories_string, plkrOS_FILE_ARRAY_SEPARATOR, &sync_directories_array, true );
    // Insert the users into the control (checked for empty there).
    m_handheld_install_ctrl->InsertDirectoryDestinations( sync_directories_array );    
    
    // Free memory occupied by arrays
    // The WX_CLEAR_ARRAY(array) macro [see dynarray.h] is required to clear out all the 
    // elements from memory of an array of structs that was built with WX_DEFINE_ARRAY.
    // All that this macro does is just to loop through the array, "delete" each element
    // to free it from memory, then mark the array as Empty().
    WX_CLEAR_ARRAY( handheld_dest_array );
    sync_directories_array.Clear();    
}
                                    

destinations_wizardpage::~destinations_wizardpage()
{
}


void destinations_wizardpage::get_user_destinations( handheld_dest_array_type& handheld_dest_array )
{
    m_handheld_install_ctrl->GetUserDestinations( handheld_dest_array );
}
    
    
void destinations_wizardpage::get_directory_destinations( wxArrayString& directory_destinations )
{
    m_handheld_install_ctrl->GetDirectoryDestinations( directory_destinations ); 
}

//----------------------------------------------------------------------------------------
// Private methods
//----------------------------------------------------------------------------------------

void destinations_wizardpage::on_wizardpage_changing( wxWizardEvent& event )
{
    // If the event was a "Next>" button event not a "<Prev" button event...
    // (wxWizardEvent::GetDirection for EVT_WIZARD_PAGE_CHANGING returns TRUE if we're
    // going forward or FALSE otherwise and for EVT_WIZARD_PAGE_CHANGED returns TRUE if we
    // came from the previous page and FALSE if we returned from the next one.
    if ( event.GetDirection() == TRUE ) 
    { 
        // ..and if the handheldinstallctrl is empty...
        if ( m_handheld_install_ctrl->IsAllDestinationsEmpty() )
        {
            wxMessageDialog need_destination_messagedialog ( this,
              _( "At least one destination is required. Click 'Add handheld..' or .'Add output directory...'." ),
              _( "Destination required" ),
              wxOK | wxICON_INFORMATION );   
            // ...then show the message dialog...
            need_destination_messagedialog.ShowModal();
            // .. and veto the wizardpagechanging event from moving off this wizardpage.
            event.Veto();
        // ...otherwise, if not empty, just continue normally.
        }
        else
        {
            return;
        }    
        
    // ..otherwise it was a "<Prev" button event, which we don't care about.    
    } else
    {
        return;
    }
}

//----------------------------------------------------------------------------------------
// End feature removal condition
//----------------------------------------------------------------------------------------

#endif // setupUSE_WIZARDS