]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
Better parbox use in tabulars, add of scrolling of inset and automatic
[lyx.git] / src / frontends / xforms / FormUrl.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
12 #include <config.h>
13
14 #include FORMS_H_LOCATION
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20
21 #include "gettext.h"
22 #include "Dialogs.h"
23 #include "FormUrl.h"
24 #include "LyXView.h"
25 #include "buffer.h"
26 #include "form_url.h"
27 #include "lyxfunc.h"
28
29 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
30         : FormCommand(lv, d, _("Url")), dialog_(0)
31 {
32         dialog_ = 0;
33         // let the dialog be shown
34         // These are permanent connections so we won't bother
35         // storing a copy because we won't be disconnecting.
36         d->showUrl.connect(slot(this, &FormUrl::showInset));
37         d->createUrl.connect(slot(this, &FormUrl::createInset));
38 }
39
40
41 FormUrl::~FormUrl()
42 {
43         free();
44         delete dialog_;
45 }
46
47
48 void FormUrl::build()
49 {
50         dialog_ = build_url();
51
52         int w = form()->w;
53         int h = form()->h;
54
55         fl_set_form_minsize(form(), w,   h);
56         fl_set_form_maxsize(form(), 2*w, h);
57 }
58
59
60 FL_FORM * const FormUrl::form() const
61 {
62         if( dialog_ ) // no need to test for dialog_->form_url
63                 return dialog_->form_url;
64         else
65                 return 0;
66 }
67
68
69 void FormUrl::update()
70 {
71         fl_set_input(dialog_->url,  params.getContents().c_str());
72         fl_set_input(dialog_->name, params.getOptions().c_str());
73
74         if ( params.getCmdName() == "url" )
75                 fl_set_button(dialog_->radio_html, 0);
76         else
77                 fl_set_button(dialog_->radio_html, 1);
78
79         if( lv_->buffer()->isReadonly() ) {
80                 fl_deactivate_object( dialog_->url );
81                 fl_deactivate_object( dialog_->name );
82                 fl_deactivate_object( dialog_->radio_html );
83                 fl_deactivate_object( dialog_->ok );
84                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
85         } else {
86                 fl_activate_object( dialog_->url );
87                 fl_activate_object( dialog_->name );
88                 fl_activate_object( dialog_->radio_html );
89                 fl_activate_object( dialog_->ok );
90                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
91         }
92 }
93
94
95 void FormUrl::apply()
96 {
97         if( lv_->buffer()->isReadonly() ) return;
98
99         params.setContents( fl_get_input(dialog_->url) );
100         params.setOptions( fl_get_input(dialog_->name) );
101
102         if (fl_get_button(dialog_->radio_html))
103                 params.setCmdName("htmlurl");
104         else
105                 params.setCmdName("url");
106
107         if( inset_ != 0 )
108         {
109                 // Only update if contents have changed
110                 if( params != inset_->params() ) {
111                         inset_->setParams( params );
112                         lv_->view()->updateInset( inset_, true );
113                 }
114         } else {
115                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
116                                              params.getAsString().c_str() );
117         }
118 }