1 /* AbiWord
2  * Copyright (C) 2000 AbiSource, Inc.
3  * Copyright (C) 2004 Martin Sevior <msevior@physics.unimelb.edu.au>
4  * Copyright (C) 2004, 2009 Hubert Figuiere
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA.
20  */
21 
22 #include <stdlib.h>
23 #include <time.h>
24 
25 #include "ut_string.h"
26 #include "ut_assert.h"
27 #include "ut_debugmsg.h"
28 
29 #include "xap_CocoaDialog_Utilities.h"
30 
31 #include "xap_App.h"
32 #include "xap_CocoaApp.h"
33 #include "xap_Frame.h"
34 
35 #include "xap_Strings.h"
36 #include "xap_Dialog_Id.h"
37 #include "xap_Dlg_History.h"
38 #include "xap_CocoaDlg_History.h"
39 
40 
41 /*****************************************************************/
42 
static_constructor(XAP_DialogFactory * pFactory,XAP_Dialog_Id dlgid)43 XAP_Dialog * XAP_CocoaDialog_History::static_constructor(XAP_DialogFactory * pFactory,
44 													 XAP_Dialog_Id dlgid)
45 {
46 	XAP_CocoaDialog_History * p = new XAP_CocoaDialog_History(pFactory,dlgid);
47 	return p;
48 }
49 
XAP_CocoaDialog_History(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id dlgid)50 XAP_CocoaDialog_History::XAP_CocoaDialog_History(XAP_DialogFactory * pDlgFactory,
51 										 XAP_Dialog_Id dlgid)
52 	: XAP_Dialog_History(pDlgFactory,dlgid)
53 {
54 }
55 
~XAP_CocoaDialog_History(void)56 XAP_CocoaDialog_History::~XAP_CocoaDialog_History(void)
57 {
58 }
59 
runModal(XAP_Frame *)60 void XAP_CocoaDialog_History::runModal(XAP_Frame * /*pFrame*/)
61 {
62 	m_dlg = [[XAP_CocoaDialog_HistoryController alloc] initFromNib];
63 
64 	// used similarly to convert between text and numeric arguments
65 	[m_dlg setXAPOwner:this];
66 
67 	// build the dialog
68 	NSWindow * window = [m_dlg window];
69 	UT_ASSERT(window);
70 
71 	_populateWindowData();
72 
73 	[NSApp runModalForWindow:window];
74 
75 	[m_dlg close];
76 	[m_dlg release];
77 	m_dlg = nil;
78 }
79 
80 
_populateWindowData(void)81 void XAP_CocoaDialog_History::_populateWindowData(void)
82 {
83 	[m_dlg populate];
84 }
85 
event_OK()86 void XAP_CocoaDialog_History::event_OK()
87 {
88 	m_answer = a_OK;
89 	[NSApp stopModal];
90 }
91 
92 
event_Cancel()93 void XAP_CocoaDialog_History::event_Cancel()
94 {
95 	m_answer = a_CANCEL;
96 	[NSApp stopModal];
97 }
98 
99 
100 @implementation XAP_CocoaDialog_HistoryController
101 - (id)initFromNib
102 {
103 	return [super initWithWindowNibName:@"xap_CocoaDlg_History"];
104 }
105 
106 -(void)discardXAP
107 {
108 	_xap = NULL;
109 }
110 
111 -(void)dealloc
112 {
113 	[super dealloc];
114 }
115 
116 - (void)setXAPOwner:(XAP_Dialog *)owner
117 {
118 	_xap = dynamic_cast<XAP_CocoaDialog_History*>(owner);
119 }
120 
addCol(NSTableView * table,XAP_CocoaDialog_History * xap,int idx)121 static void addCol(NSTableView *table, XAP_CocoaDialog_History* xap, int idx)
122 {
123 	NSTableColumn *col = [[NSTableColumn alloc] initWithIdentifier:[NSNumber numberWithLong:idx]];
124 	[col setEditable:NO];
125 	[[col headerCell] setTitle:[NSString stringWithUTF8String:xap->getListHeader(idx)]];
126 	[table addTableColumn:col];
127 	[col release];
128 }
129 
130 
131 -(void)windowDidLoad
132 {
133 	if (_xap) {
134 		const XAP_StringSet *pSS = XAP_App::getApp()->getStringSet();
135 		LocalizeControl([self window], pSS, XAP_STRING_ID_DLG_History_WindowLabel);
136 		LocalizeControl(_okBtn, pSS, XAP_STRING_ID_DLG_OK);
137 		LocalizeControl(_cancelBtn, pSS, XAP_STRING_ID_DLG_Cancel);
138 		LocalizeControl(_historyBox, pSS, XAP_STRING_ID_DLG_History_DocumentDetails);
139 
140 		addCol(_historyList, _xap, 0);
141 		addCol(_historyList, _xap, 1);
142 		addCol(_historyList, _xap, 2);
143 	}
144 }
145 
146 
147 - (IBAction)cancelAction:(id)sender
148 {
149 	UT_UNUSED(sender);
150 	_xap->event_Cancel();
151 }
152 
153 - (IBAction)okAction:(id)sender
154 {
155 	UT_UNUSED(sender);
156 	_xap->event_OK();
157 }
158 
159 - (IBAction)historySelect:(id)sender
160 {
161 	UT_uint32 item = [sender selectedRow];
162 	UT_DEBUGMSG(("Value of id selected %d \n",item));
163 	_xap->setSelectionId(_xap->getListItemId(item));
164 }
165 
166 
167 - (void)populate
168 {
169 	[_docNameLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(0)]];
170 	[_docNameData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(0)]];
171 	[_versionLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(1)]];
172 	[_versionData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(1)]];
173 	[_createdLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(2)]];
174 	[_createdData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(2)]];
175 	[_lastSavedLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(3)]];
176 	[_lastSavedData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(3)]];
177 	[_editTimeLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(4)]];
178 	[_editTimeData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(4)]];
179 	[_identifierLabel setStringValue:[NSString stringWithUTF8String:_xap->getHeaderLabel(5)]];
180 	[_identifierData setStringValue:[NSString stringWithUTF8String:_xap->getHeaderValue(5)]];
181 	[_historyBox setTitle:[NSString stringWithUTF8String:_xap->getListTitle()]];
182 	[_historyList setDataSource:self];
183 }
184 
185 - (id)tableView:(NSTableView *)aTableView
186     objectValueForTableColumn:(NSTableColumn *)aTableColumn
187     row:(int)rowIndex
188 {
189 	UT_UNUSED(aTableView);
190 	id i = [aTableColumn identifier];
191 	int col = [ i longValue];
192 	NSString *s = [NSString stringWithUTF8String:_xap->getListValue(rowIndex, col)];
193 
194 	return s;
195 }
196 
197 
198 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
199 {
200 	UT_UNUSED(aTableView);
201 	return _xap->getListItemCount();
202 }
203 
204 
205 @end
206 
207