Listing 6
// Step 1. The data you use internally
// employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
struct employee {
std::string first_name;
std::string last_name;
int id;
unsigned long salary;
// ... etc.
};
#endif
// Step 2a. Create the correspondence class
// (what needs to be shown/edited visually)
// ui_employee.h
#ifndef UI_EMPLOYEE_H
#define UI_EMPLOYEE_H
#include "employee.h"
struct ui_empl_corresp : save_dlg::corresp {
// empl - the data we need to show in our Dialog
ui_empl_corresp( employee & empl);
};
#endif
// Step 2b. Implement the correspondence
// ui_employee.cpp
#include "ui_employee.h"
// ... eventually here have your validators
void valid_name(
const std::string & old_name, const std::string & new_name,
save_dlg::info<employee> & info) {
// ...
}
ui_empl_corresp::ui_empl_correp(employee &empl) {
// add our [in/out] data
add_var(empl);
// create correspondence from data to controls
add_corresp( &employee::first_name, ID_first_name);
add_corresp( &employee::last_name, ID_last_name);
// add validators, if any
add_validator(ID_first_name, &valid_name, validate::on_exit);
add_validator(ID_last_name, &valid_name, validate::on_exit);
}
// Step 3. Use in code
#include "ui_employee.h"
// ...
employee empl;
// ... fill it
// show different views:
// Show all user details
create_save_dlg(IDD_empl_details, ui_corresp(empl), parent_wnd);
// Or, show only summary
create_save_dlg(IDD_empl_summary, ui_corresp(empl), parent_wnd);
// Or, show only what the Accountant is allowed to see
// (the money :))
create_save_dlg(IDD_empl_acc, ui_corresp(empl), parent_wnd);
// Or, show his address
create_save_dlg(IDD_empl_address, ui_corresp(empl), parent_wnd);