]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
Angus's insetref-patch and a small fix.
[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), minh(0), minw(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         // XFORMS bug workaround
53         // Define the min/max dimensions. Actually applied in update()
54         minw = form()->w; minh = form()->h;
55 }
56
57
58 FL_FORM * const FormUrl::form() const
59 {
60         if( dialog_ ) // no need to test for dialog_->form_url
61                 return dialog_->form_url;
62         else
63                 return 0;
64 }
65
66
67 void FormUrl::update()
68 {
69         fl_set_form_minsize(form(), minw, minh);
70         fl_set_form_maxsize(form(), 2*minw, minh);
71
72         fl_set_input(dialog_->url,  params.getContents().c_str());
73         fl_set_input(dialog_->name, params.getOptions().c_str());
74
75         if ( params.getCmdName() == "url" )
76                 fl_set_button(dialog_->radio_html, 0);
77         else
78                 fl_set_button(dialog_->radio_html, 1);
79
80         if( lv_->buffer()->isReadonly() ) {
81                 fl_deactivate_object( dialog_->url );
82                 fl_deactivate_object( dialog_->name );
83                 fl_deactivate_object( dialog_->radio_html );
84                 fl_deactivate_object( dialog_->ok );
85                 fl_set_object_lcol( dialog_->ok, FL_INACTIVE );
86         } else {
87                 fl_activate_object( dialog_->url );
88                 fl_activate_object( dialog_->name );
89                 fl_activate_object( dialog_->radio_html );
90                 fl_activate_object( dialog_->ok );
91                 fl_set_object_lcol( dialog_->ok, FL_BLACK );
92         }
93 }
94
95
96 void FormUrl::apply()
97 {
98         if( lv_->buffer()->isReadonly() ) return;
99
100         params.setContents( fl_get_input(dialog_->url) );
101         params.setOptions( fl_get_input(dialog_->name) );
102
103         if (fl_get_button(dialog_->radio_html))
104                 params.setCmdName("htmlurl");
105         else
106                 params.setCmdName("url");
107
108         if( inset_ != 0 )
109         {
110                 // Only update if contents have changed
111                 if( params != inset_->params() ) {
112                         inset_->setParams( params );
113                         lv_->view()->updateInset( inset_, true );
114                 }
115         } else {
116                 lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL,
117                                              params.getAsString().c_str() );
118         }
119 }