]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabularCreate.C
More pref work from Angus
[lyx.git] / src / frontends / xforms / FormTabularCreate.C
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000 The LyX Team.
8  *
9  * ======================================================
10  */
11 /* FormTabularCreate.C
12  * FormTabularCreate Interface Class Implementation
13  */
14
15 #include <config.h>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "FormTabularCreate.h"
22 #include "form_tabular_create.h"
23 #include "BufferView.h"
24 #include "Dialogs.h"
25 #include "LyXView.h"
26 #include "insets/insettabular.h"
27
28 FormTabularCreate::FormTabularCreate(LyXView * lv, Dialogs * d)
29         : FormBaseBD(lv, d, _("Insert Tabular")),
30           dialog_(0)
31 {
32         // let the dialog be shown
33         // This is a permanent connection so we won't bother
34         // storing a copy because we won't be disconnecting.
35         d->showTabularCreate.connect(slot(this, &FormTabularCreate::show));
36 }
37
38
39 FormTabularCreate::~FormTabularCreate()
40 {
41         delete dialog_;
42 }
43
44
45 FL_FORM * FormTabularCreate::form() const
46 {
47         if ( dialog_ ) return dialog_->form;
48         return 0;
49 }
50
51
52 void FormTabularCreate::connect()
53 {
54         bc_.valid(true);
55         FormBaseBD::connect();
56 }
57
58
59 void FormTabularCreate::build()
60 {
61         dialog_ = build_tabular_create();
62
63         // Workaround dumb xforms sizing bug
64         minw_ = form()->w;
65         minh_ = form()->h;
66
67         fl_set_slider_bounds(dialog_->slider_rows, 1, 50);
68         fl_set_slider_bounds(dialog_->slider_columns, 1, 50);
69         fl_set_slider_value(dialog_->slider_rows, 5);
70         fl_set_slider_value(dialog_->slider_columns, 5);
71         fl_set_slider_precision(dialog_->slider_rows, 0);
72         fl_set_slider_precision(dialog_->slider_columns, 0);
73
74         // manage the ok, apply and cancel/close buttons
75         bc_.setOK(dialog_->button_ok);
76         bc_.setApply(dialog_->button_apply);
77         bc_.setCancel(dialog_->button_cancel);
78         bc_.refresh();
79 }
80
81
82 void FormTabularCreate::apply()
83 {
84         int ysize = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
85         int xsize = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
86
87         InsetTabular * in = new InsetTabular( *lv_->buffer(), xsize, ysize );
88         if (!lv_->view()->open_new_inset(in)) {
89                 delete in;
90         }
91 }