]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormTabularCreate.C
6fd5d1a7055302250dabd8aea5f3193065be1cf6
[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 "buffer.h"
24 #include "BufferView.h"
25 #include "Dialogs.h"
26 #include "LyXView.h"
27 #include "insets/insettabular.h"
28
29 FormTabularCreate::FormTabularCreate(LyXView * lv, Dialogs * d)
30         : FormBaseBD(lv, d, _("Insert Tabular"),
31                      new OkApplyCancelReadOnlyPolicy),
32           dialog_(0)
33 {
34         // let the dialog be shown
35         // This is a permanent connection so we won't bother
36         // storing a copy because we won't be disconnecting.
37         d->showTabularCreate.connect(slot(this, &FormTabularCreate::show));
38 }
39
40
41 FormTabularCreate::~FormTabularCreate()
42 {
43         delete dialog_;
44 }
45
46
47 FL_FORM * FormTabularCreate::form() const
48 {
49         if (dialog_) return dialog_->form;
50         return 0;
51 }
52
53
54 void FormTabularCreate::connect()
55 {
56         bc_.valid(true);
57         FormBaseBD::connect();
58 }
59
60
61 void FormTabularCreate::build()
62 {
63         dialog_ = build_tabular_create();
64
65         // Workaround dumb xforms sizing bug
66         minw_ = form()->w;
67         minh_ = form()->h;
68
69         fl_set_slider_bounds(dialog_->slider_rows, 1, 50);
70         fl_set_slider_bounds(dialog_->slider_columns, 1, 50);
71         fl_set_slider_value(dialog_->slider_rows, 5);
72         fl_set_slider_value(dialog_->slider_columns, 5);
73         fl_set_slider_precision(dialog_->slider_rows, 0);
74         fl_set_slider_precision(dialog_->slider_columns, 0);
75
76         // Manage the ok, apply and cancel/close buttons
77         bc_.setOK(dialog_->button_ok);
78         bc_.setApply(dialog_->button_apply);
79         bc_.setCancel(dialog_->button_cancel);
80         bc_.refresh();
81 }
82
83
84 void FormTabularCreate::apply()
85 {
86         int ysize = int(fl_get_slider_value(dialog_->slider_columns) + 0.5);
87         int xsize = int(fl_get_slider_value(dialog_->slider_rows) + 0.5);
88
89         InsetTabular * in = new InsetTabular( *lv_->buffer(), xsize, ysize );
90         if (!lv_->view()->open_new_inset(in)) {
91                 delete in;
92         }
93 }
94
95
96 void FormTabularCreate::update()
97 {
98         bc_.readOnly(lv_->buffer()->isReadonly());
99 }