]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormCharacter.C
Implementation of controller-view split for FormCharacter.
[lyx.git] / src / frontends / xforms / FormCharacter.C
1 /**
2  * \file FormCharacter.C
3  * Copyright 2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Edwin Leuven,  leuven@fee.uva.nl
7  * \author Angus Leeming, a.leeming@ic.ac.uk
8  */
9
10 #include <vector>
11
12 #ifdef __GNUG_
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "xformsBC.h"
19 #include "ControlCharacter.h"
20 #include "FormCharacter.h"
21 #include "form_character.h"
22 #include "gettext.h"
23 #include "combox.h"
24 #include "helper_funcs.h"
25
26 using std::vector;
27 using std::back_inserter;
28 using std::transform;
29
30 typedef FormCB<ControlCharacter, FormDB<FD_form_character> > base_class;
31
32 FormCharacter::FormCharacter(ControlCharacter & c)
33         : base_class(c, _("Character Layout"))
34 {}
35
36
37 void FormCharacter::ComboInputCB(int, void * v, Combox * combox)
38 {
39         FormCharacter * pre = static_cast<FormCharacter*>(v);
40         pre->InputCB(reinterpret_cast<FL_OBJECT *>(combox), 0);
41 }
42
43 void FormCharacter::build()
44 {
45         dialog_.reset(build_character());
46
47         vector<ControlCharacter::FamilyPair> const family = getFamilyData();
48         vector<ControlCharacter::SeriesPair> const series = getSeriesData();
49         vector<ControlCharacter::ShapePair>  const shape  = getShapeData();
50         vector<ControlCharacter::SizePair>   const size   = getSizeData();
51         vector<ControlCharacter::BarPair>    const bar    = getBarData();
52         vector<ControlCharacter::ColorPair>  const color  = getColorData();
53         vector<string> const language = getLanguageData();
54
55         // Store the enums for later
56         family_ = getSecond(family);
57         series_ = getSecond(series);
58         shape_ = getSecond(shape);
59         size_ = getSecond(size);
60         bar_ = getSecond(bar);
61         color_ = getSecond(color);
62
63         // create a string of entries " entry1 | entry2 | entry3 | entry4 "
64         // with which to initialise the xforms choice object.
65         string choice = " " + getStringFromVector(getFirst(family), " | ") +" ";
66         fl_addto_choice(dialog_->choice_family, choice.c_str());
67
68         choice = " " + getStringFromVector(getFirst(series), " | ") + " ";
69         fl_addto_choice(dialog_->choice_series, choice.c_str());
70
71         choice = " " + getStringFromVector(getFirst(shape), " | ") + " ";
72         fl_addto_choice(dialog_->choice_shape, choice.c_str());
73
74         choice = " " + getStringFromVector(getFirst(size), " | ") + " ";
75         fl_addto_choice(dialog_->choice_size, choice.c_str());
76
77         choice = " " + getStringFromVector(getFirst(bar), " | ") + " ";
78         fl_addto_choice(dialog_->choice_bar, choice.c_str());
79
80         choice = " " + getStringFromVector(getFirst(color), " | ") + " ";
81         fl_addto_choice(dialog_->choice_color, choice.c_str());
82
83         // xforms appears to need this to prevent a crash...
84         // fl_addto_choice(dialog_->choice_language,
85         //              _(" English %l| German | French "));
86
87         // insert default language box manually
88         fl_addto_form(dialog_->form);
89                 FL_OBJECT * ob = dialog_->choice_language;
90                 combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST));
91                 combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250);
92                 combo_language2_->shortcut("#L", 1);
93                 combo_language2_->setcallback(ComboInputCB, this);
94         fl_end_form();
95
96         // build up the combox entries
97         for (vector<string>::const_iterator cit = language.begin(); 
98              cit != language.end(); ++cit) {
99                 combo_language2_->addto(*cit);
100         }
101         combo_language2_->select_text(*language.begin());
102
103         // Manage the ok, apply and cancel/close buttons
104         bc().setApply(dialog_->button_apply);
105         bc().setCancel(dialog_->button_close);
106         bc().refresh();
107         bc().addReadOnly(dialog_->check_toggle_all);
108 }
109
110
111 void FormCharacter::apply()
112 {
113         int pos = fl_get_choice(dialog_->choice_family);
114         controller().setFamily(family_[pos-1]);
115
116         pos = fl_get_choice(dialog_->choice_series);
117         controller().setSeries(series_[pos-1]);
118    
119         pos = fl_get_choice(dialog_->choice_shape);
120         controller().setShape(shape_[pos-1]);
121
122         pos = fl_get_choice(dialog_->choice_size);
123         controller().setSize(size_[pos-1]);
124    
125         pos = fl_get_choice(dialog_->choice_bar);
126         controller().setBar(bar_[pos-1]);
127    
128         pos = fl_get_choice(dialog_->choice_color);
129         controller().setColor(color_[pos-1]);
130
131         controller().setLanguage(combo_language2_->getline());
132
133         bool const toggleall = fl_get_button(dialog_->check_toggle_all);
134         controller().setToggleAll(toggleall);
135 }