]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormUrl.C
The forms resize patch, and small updates
[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 "Dialogs.h"
22 #include "FormUrl.h"
23 #include "LyXView.h"
24 #include "buffer.h"
25 #include "form_url.h"
26 #include "lyxfunc.h"
27
28 FormUrl::FormUrl(LyXView * lv, Dialogs * d)
29         : FormCommand(lv, d, _("Url")), dialog_(0)
30 {
31         // let the dialog be shown
32         // These are permanent connections so we won't bother
33         // storing a copy because we won't be disconnecting.
34         d->showUrl.connect(slot(this, &FormUrl::showInset));
35         d->createUrl.connect(slot(this, &FormUrl::createInset));
36 }
37
38
39 FormUrl::~FormUrl()
40 {
41         delete dialog_;
42 }
43
44
45 FL_FORM * FormUrl::form() const
46 {
47         if ( dialog_ ) return dialog_->form;
48         return 0;
49 }
50
51
52 void FormUrl::connect()
53 {
54         fl_set_form_maxsize( form(), 2*minw_, minh_ );
55         FormCommand::connect();
56 }
57         
58
59 void FormUrl::build()
60 {
61         dialog_ = build_url();
62
63 #ifdef WITH_WARNINGS
64 #warning use the buttoncontroller
65 #endif
66         // Workaround dumb xforms sizing bug
67         minw_ = form()->w;
68         minh_ = form()->h;
69 }
70
71
72 void FormUrl::update(bool switched)
73 {
74         if (switched) {
75                 hide();
76                 return;
77         }
78
79         fl_set_input(dialog_->url,  params.getContents().c_str());
80         fl_set_input(dialog_->name, params.getOptions().c_str());
81
82         if ( params.getCmdName() == "url" )
83                 fl_set_button(dialog_->radio_html, 0);
84         else
85                 fl_set_button(dialog_->radio_html, 1);
86
87         if ( lv_->buffer()->isReadonly() ) {
88                 fl_deactivate_object( dialog_->url );
89                 fl_deactivate_object( dialog_->name );
90                 fl_deactivate_object( dialog_->radio_html );
91                 fl_deactivate_object( dialog_->button_ok );
92                 fl_set_object_lcol( dialog_->button_ok, FL_INACTIVE );
93         } else {
94                 fl_activate_object( dialog_->url );
95                 fl_activate_object( dialog_->name );
96                 fl_activate_object( dialog_->radio_html );
97                 fl_activate_object( dialog_->button_ok );
98                 fl_set_object_lcol( dialog_->button_ok, FL_BLACK );
99         }
100 }
101
102
103 void FormUrl::apply()
104 {
105         if (lv_->buffer()->isReadonly()) return;
106
107         params.setContents(fl_get_input(dialog_->url));
108         params.setOptions(fl_get_input(dialog_->name));
109
110         if (fl_get_button(dialog_->radio_html))
111                 params.setCmdName("htmlurl");
112         else
113                 params.setCmdName("url");
114
115         if (inset_ != 0) {
116                 // Only update if contents have changed
117                 if (params != inset_->params()) {
118                         inset_->setParams(params);
119                         lv_->view()->updateInset(inset_, true);
120                 }
121         } else {
122                 lv_->getLyXFunc()->Dispatch(LFUN_INSERT_URL,
123                                             params.getAsString());
124         }
125 }