Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_Encoding.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998-2001 AbiSource, Inc.
3 * Copyright (C) 2003 Hubert Figuiere
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301 USA.
19 */
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include "ut_string.h"
25 #include "ut_debugmsg.h"
26 #include "xap_CocoaDialog_Utilities.h"
27
28 #include "xap_App.h"
29 #include "xap_CocoaApp.h"
30 #include "xap_CocoaFrame.h"
31
32 #include "xap_Dialog_Id.h"
33 #include "xap_CocoaDlg_Encoding.h"
34
35
36 class XAP_Encoding_Proxy: public XAP_GenericListChooser_Proxy
37 {
38 public:
39 XAP_Encoding_Proxy (XAP_CocoaDialog_Encoding* dlg)
40 : XAP_GenericListChooser_Proxy(),
41 m_dlg(dlg)
42 {
43 };
44 virtual void okAction ()
45 {
46 m_dlg->event_OK();
47 };
48 virtual void cancelAction ()
49 {
50 m_dlg->event_Cancel();
51 };
52 virtual void selectAction ()
53 {
54 m_dlg->event_OK();
55 };
56 private:
57 XAP_CocoaDialog_Encoding* m_dlg;
58 };
59
60 /*****************************************************************/
61
62 XAP_Dialog * XAP_CocoaDialog_Encoding::static_constructor(XAP_DialogFactory * pFactory,
63 XAP_Dialog_Id dlgid)
64 {
65 XAP_CocoaDialog_Encoding * p = new XAP_CocoaDialog_Encoding(pFactory,dlgid);
66 return p;
67 }
68
69 XAP_CocoaDialog_Encoding::XAP_CocoaDialog_Encoding(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id dlgid)
70 : XAP_Dialog_Encoding(pDlgFactory,dlgid),
71 m_dataSource(nil),
72 m_dlg(nil)
73 {
74
75 }
76
77 XAP_CocoaDialog_Encoding::~XAP_CocoaDialog_Encoding(void)
78 {
79 }
80
81
82 /*****************************************************************/
83
84 void XAP_CocoaDialog_Encoding::runModal(XAP_Frame * /*pFrame*/)
85 {
86
87 NSWindow* window;
88 m_dlg = [XAP_GenericListChooser_Controller loadFromNib];
89 XAP_Encoding_Proxy proxy(this);
90 [m_dlg setXAPProxy:&proxy];
91 m_dataSource = [[XAP_StringListDataSource alloc] init];
92
93 window = [m_dlg window];
94 const XAP_StringSet * pSS = m_pApp->getStringSet();
95 [m_dlg setTitle:LocalizedString(pSS, XAP_STRING_ID_DLG_UENC_EncTitle)];
96 [m_dlg setLabel:LocalizedString(pSS, XAP_STRING_ID_DLG_UENC_EncLabel)];
97
98 // Populate the window's data items
99 _populateWindowData();
100 [m_dlg setDataSource:m_dataSource];
101
102
103 [NSApp runModalForWindow:window];
104 [m_dlg close];
105
106 [m_dataSource release];
107
108 m_dlg = nil;
109 }
110
111 void XAP_CocoaDialog_Encoding::event_OK(void)
112 {
113 // Query the list for its selection.
114 int row = [m_dlg selected];
115
116 if (row >= 0)
117 _setSelectionIndex((UT_uint32) row);
118
119 _setEncoding (_getAllEncodings()[row]);
120 _setAnswer (XAP_Dialog_Encoding::a_OK);
121 [NSApp stopModal];
122 }
123
124 void XAP_CocoaDialog_Encoding::event_Cancel(void)
125 {
126 _setAnswer (XAP_Dialog_Encoding::a_CANCEL);
127 [NSApp stopModal];
128 }
129
130 /*****************************************************************/
131
132
133 void XAP_CocoaDialog_Encoding::_populateWindowData(void)
134 {
135 // We just do one thing here, which is fill the list with
136 // all the windows.
137
138 for (UT_uint32 i = 0; i < _getEncodingsCount(); i++)
139 {
140 const gchar* s = _getAllEncodings()[i];
141
142 [m_dataSource addString:[NSString stringWithUTF8String:s]];
143 }
144
145 // Select the one we're in
146 [m_dlg setSelected:_getSelectionIndex()];
147 }
148
149
150