Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_ListDocuments.cpp

raw
1 /* AbiWord
2 * Copyright (C) 2000 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <time.h>
22
23 #include "ut_string.h"
24 #include "ut_assert.h"
25 #include "ut_debugmsg.h"
26
27 #include "xap_CocoaDialog_Utilities.h"
28
29 #include "xap_App.h"
30 #include "xap_CocoaApp.h"
31 #include "xap_Frame.h"
32
33 #include "xap_Strings.h"
34 #include "xap_Dialog_Id.h"
35 #include "xap_Dlg_ListDocuments.h"
36 #include "xap_CocoaDlg_ListDocuments.h"
37 #import "xap_Cocoa_NSTableUtils.h"
38 #import "xap_GenericListChooser_Controller.h"
39
40 /*****************************************************************/
41
42 class XAP_DocList_Proxy: public XAP_GenericListChooser_Proxy
43 {
44 public:
45 XAP_DocList_Proxy (XAP_CocoaDialog_ListDocuments* dlg)
46 : XAP_GenericListChooser_Proxy(),
47 m_dlg(dlg)
48 {
49 };
50 virtual void okAction ()
51 {
52 m_dlg->event_OK();
53 };
54 virtual void cancelAction ()
55 {
56 m_dlg->event_Cancel();
57 };
58 virtual void selectAction ()
59 {
60 m_dlg->event_OK();
61 };
62 private:
63 XAP_CocoaDialog_ListDocuments* m_dlg;
64 };
65
66
67 /*****************************************************************/
68
69 XAP_Dialog * XAP_CocoaDialog_ListDocuments::static_constructor(XAP_DialogFactory * pFactory,
70 XAP_Dialog_Id dlgid)
71 {
72 XAP_CocoaDialog_ListDocuments * p = new XAP_CocoaDialog_ListDocuments(pFactory,dlgid);
73 return p;
74 }
75
76 XAP_CocoaDialog_ListDocuments::XAP_CocoaDialog_ListDocuments(XAP_DialogFactory * pDlgFactory,
77 XAP_Dialog_Id dlgid)
78 : XAP_Dialog_ListDocuments(pDlgFactory,dlgid)
79 {
80 }
81
82 XAP_CocoaDialog_ListDocuments::~XAP_CocoaDialog_ListDocuments(void)
83 {
84 }
85
86 void XAP_CocoaDialog_ListDocuments::event_OK(void)
87 {
88 _setSelDocumentIndx([m_dlg selected]);
89 [NSApp stopModal];
90 }
91
92
93 void XAP_CocoaDialog_ListDocuments::event_Cancel(void)
94 {
95 [NSApp stopModal];
96 }
97
98
99 void XAP_CocoaDialog_ListDocuments::_populateWindowData(void)
100 {
101 const char * untitled = "(untitled)";
102
103 UT_uint32 c = _getDocumentCount();
104 UT_uint32 i;
105
106 [m_dataSource removeAllStrings];
107 for (i = 0; i < c; i++)
108 {
109 const char * name = _getNthDocumentName(i);
110 [m_dataSource addString:[NSString stringWithUTF8String:(name ? name : untitled)]];
111 }
112 }
113
114
115 void XAP_CocoaDialog_ListDocuments::runModal(XAP_Frame * /*pFrame*/)
116 {
117 NSWindow* window;
118 m_dlg = [XAP_GenericListChooser_Controller loadFromNib];
119 XAP_DocList_Proxy proxy(this);
120 [m_dlg setXAPProxy:&proxy];
121 m_dataSource = [[XAP_StringListDataSource alloc] init];
122
123 window = [m_dlg window];
124 // const XAP_StringSet * pSS = m_pApp->getStringSet();
125 [m_dlg setTitle:[NSString stringWithUTF8String:_getTitle()]];
126 [m_dlg setLabel:[NSString stringWithUTF8String:_getHeading()]];
127
128 // Populate the window's data items
129 _populateWindowData();
130 [m_dlg setDataSource:m_dataSource];
131
132
133 [NSApp runModalForWindow:window];
134 [m_dlg close];
135
136 [m_dataSource release];
137
138 m_dlg = nil;
139 }