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