1 //
2 // "$Id: DiffOpenWindow.cxx 407 2006-11-13 18:54:02Z mike $"
3 //
4 // DiffOpenWindow widget code.
5 //
6 // Copyright 2005-2006 by Michael Sweet.
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License v2 as published
10 // by the Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // Contents:
18 //
19 //   DiffOpenWindow::DiffOpenWindow() - Create an open/compare window.
20 //   DiffOpenWindow::compare_cb()     - Confirm the open/compare.
21 //   DiffOpenWindow::cancel_cb()      - Cancel the open/compare.
22 //   DiffOpenWindow::dc_cb()          - Handle selections in either chooser.
23 //   DiffOpenWindow::resize()         - Resize the window.
24 //   DiffOpenWindow::show()           - Show the window.
25 //
26 
27 #include "DiffOpenWindow.h"
28 
29 
30 //
31 // 'DiffOpenWindow::DiffOpenWindow()' - Create an open/compare window.
32 //
33 
DiffOpenWindow(const char * v1,const char * v2)34 DiffOpenWindow::DiffOpenWindow(
35     const char *v1,			// I - First value
36     const char *v2)			// I - Second value
37   : Fl_Double_Window(640, 480, "Open/Compare"),
38     dc1_(10, 25, 305, 410, "File/Directory 1:"),
39     dc2_(325, 25, 305, 410, "File/Directory 2:"),
40     compare_(435, 445, 120, 25, "Open/Compare"),
41     cancel_(565, 445, 65, 25, "Cancel")
42 {
43   end();
44   modal();
45 
46   resizable(this);
47   size_range(255, 225, Fl::w(), Fl::h());
48 
49   dc1_.align(FL_ALIGN_TOP_LEFT);
50   dc1_.callback((Fl_Callback *)dc_cb, this);
51   dc1_.labelfont(FL_HELVETICA_BOLD);
52   dc1_.value(v1);
53 
54   dc2_.align(FL_ALIGN_TOP_LEFT);
55   dc2_.callback((Fl_Callback *)dc_cb, this);
56   dc2_.labelfont(FL_HELVETICA_BOLD);
57   dc2_.value(v2);
58 
59   compare_.callback((Fl_Callback *)compare_cb, this);
60   compare_.shortcut(FL_Enter);
61 
62   cancel_.callback((Fl_Callback *)cancel_cb, this);
63 }
64 
65 
66 //
67 // 'DiffOpenWindow::compare_cb()' - Confirm the open/compare.
68 //
69 
70 void
compare_cb(Fl_Button * b,DiffOpenWindow * dow)71 DiffOpenWindow::compare_cb(
72     Fl_Button      *b,			// I - Open/compare button
73     DiffOpenWindow *dow)		// I - Diff open window
74 {
75   dow->hide();
76 }
77 
78 
79 //
80 // 'DiffOpenWindow::cancel_cb()' - Cancel the open/compare.
81 //
82 
83 void
cancel_cb(Fl_Button * b,DiffOpenWindow * dow)84 DiffOpenWindow::cancel_cb(
85     Fl_Button      *b,			// I - Cancel button
86     DiffOpenWindow *dow)		// I - Diff open window
87 {
88   dow->dc1_.deselect();
89   dow->dc2_.deselect();
90 
91   dow->hide();
92 }
93 
94 
95 //
96 // 'DiffOpenWindow::dc_cb()' - Handle selections in either chooser.
97 //
98 
99 void
dc_cb(DiffChooser * dc,DiffOpenWindow * dow)100 DiffOpenWindow::dc_cb(
101     DiffChooser    *dc,			// I - Diff chooser
102     DiffOpenWindow *dow)		// I - Diff open window
103 {
104   if (dow->dc1_.count())
105   {
106     dow->compare_.activate();
107 
108     if (Fl::event_clicks())
109       dow->do_callback();
110   }
111   else
112     dow->compare_.deactivate();
113 }
114 
115 
116 //
117 // 'DiffOpenWindow::resize()' - Resize the window.
118 //
119 
120 void
resize(int X,int Y,int W,int H)121 DiffOpenWindow::resize(int X,		// I - X position
122                        int Y,		// I - Y position
123 		       int W,		// I - Width
124 		       int H)		// I - Height
125 {
126   Fl_Double_Window::resize(X, Y, W, H);
127 
128   dc1_.resize(10, 25, (W - 30) / 2, H - 70);
129   dc2_.resize(20 + (W - 30) / 2, 25, (W - 30) / 2, H - 70);
130   compare_.resize(W - 205, H - 35, 120, 25);
131   cancel_.resize(W - 75, H - 35, 65, 25);
132 }
133 
134 
135 //
136 // 'DiffOpenWindow::show()' - Show the window.
137 //
138 
139 void
show()140 DiffOpenWindow::show()
141 {
142   if (dc1_.count())
143     compare_.activate();
144   else
145     compare_.deactivate();
146 
147   hotspot(this);
148 
149   Fl_Double_Window::show();
150 }
151 
152 
153 //
154 // End of "$Id: DiffOpenWindow.cxx 407 2006-11-13 18:54:02Z mike $".
155 //
156