Debian Codegraph @

src/af/xap/cocoa/xap_CocoaDlg_WindowMore.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 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 "ut_string.h"
22 #include "ut_assert.h"
23 #include "ut_debugmsg.h"
24
25 // This header defines some functions for Cocoa dialogs,
26 // like centering them, measuring them, etc.
27 #include "xap_CocoaDialog_Utilities.h"
28
29 #include "xap_App.h"
30 #include "xap_CocoaApp.h"
31 #include "xap_CocoaFrame.h"
32
33 #include "xap_Dialog_Id.h"
34 #include "xap_Dlg_WindowMore.h"
35 #include "xap_CocoaDlg_WindowMore.h"
36
37
38 class XAP_WindowMore_Proxy: public XAP_GenericListChooser_Proxy
39 {
40 public:
41 XAP_WindowMore_Proxy (XAP_CocoaDialog_WindowMore* dlg)
42 : XAP_GenericListChooser_Proxy(),
43 m_dlg(dlg)
44 {
45 };
46 virtual void okAction ()
47 {
48 m_dlg->event_OK();
49 };
50 virtual void cancelAction ()
51 {
52 m_dlg->event_Cancel();
53 };
54 virtual void selectAction ()
55 {
56 m_dlg->event_DoubleClick();
57 };
58 private:
59 XAP_CocoaDialog_WindowMore* m_dlg;
60 };
61
62 /*****************************************************************/
63
64 XAP_Dialog * XAP_CocoaDialog_WindowMore::static_constructor(XAP_DialogFactory * pFactory,
65 XAP_Dialog_Id dlgid)
66 {
67 XAP_CocoaDialog_WindowMore * p = new XAP_CocoaDialog_WindowMore(pFactory,dlgid);
68 return p;
69 }
70
71 XAP_CocoaDialog_WindowMore::XAP_CocoaDialog_WindowMore(XAP_DialogFactory * pDlgFactory,
72 XAP_Dialog_Id dlgid)
73 : XAP_Dialog_WindowMore(pDlgFactory,dlgid),
74 m_dataSource(nil),
75 m_dlg(nil)
76 {
77 }
78
79 XAP_CocoaDialog_WindowMore::~XAP_CocoaDialog_WindowMore(void)
80 {
81 }
82
83
84 /*****************************************************************/
85
86 void XAP_CocoaDialog_WindowMore::runModal(XAP_Frame * pFrame)
87 {
88 // Initialize member so we know where we are now
89 m_ndxSelFrame = m_pApp->findFrame(pFrame);
90 UT_ASSERT(m_ndxSelFrame >= 0);
91
92 NSWindow* window;
93 m_dlg = [XAP_GenericListChooser_Controller loadFromNib];
94 XAP_WindowMore_Proxy proxy(this);
95 [m_dlg setXAPProxy:&proxy];
96 m_dataSource = [[XAP_StringListDataSource alloc] init];
97
98 window = [m_dlg window];
99 const XAP_StringSet * pSS = m_pApp->getStringSet();
100 std::string label;
101 pSS->getValueUTF8(XAP_STRING_ID_DLG_MW_MoreWindows, label);
102 [m_dlg setTitle:[NSString stringWithUTF8String:label.c_str()]];
103 pSS->getValueUTF8(XAP_STRING_ID_DLG_MW_Activate, label);
104 [m_dlg setLabel:[NSString stringWithUTF8String:label.c_str()]];
105
106 // Populate the window's data items
107 _populateWindowData();
108 [m_dlg setDataSource:m_dataSource];
109
110
111 [NSApp runModalForWindow:window];
112 [m_dlg close];
113
114 [m_dataSource release];
115
116 m_dlg = nil;
117 }
118
119 void XAP_CocoaDialog_WindowMore::event_OK(void)
120 {
121 // Query the list for its selection.
122 int row = [m_dlg selected];
123
124 if (row >= 0)
125 m_ndxSelFrame = (UT_uint32) row;
126
127 m_answer = XAP_Dialog_WindowMore::a_OK;
128 [NSApp stopModal];
129 }
130
131 void XAP_CocoaDialog_WindowMore::event_Cancel(void)
132 {
133 m_answer = XAP_Dialog_WindowMore::a_CANCEL;
134 [NSApp stopModal];
135 }
136
137 void XAP_CocoaDialog_WindowMore::event_DoubleClick(void)
138 {
139 // Query the list for its selection.
140 int row = [m_dlg selected];
141
142 // If it found something, return with it
143 if (row >= 0)
144 {
145 m_ndxSelFrame = (UT_uint32) row;
146 event_OK();
147 }
148 }
149
150
151
152 void XAP_CocoaDialog_WindowMore::_populateWindowData(void)
153 {
154 // We just do one thing here, which is fill the list with
155 // all the windows.
156
157 for (UT_sint32 i = 0; i < m_pApp->getFrameCount(); i++)
158 {
159 XAP_Frame * f = m_pApp->getFrame(i);
160 UT_ASSERT(f);
161 UT_UTF8String s = f->getTitle();
162
163 [m_dataSource addString:[NSString stringWithUTF8String:s.utf8_str()]];
164 }
165
166 // Select the one we're in
167 [m_dlg setSelected:m_ndxSelFrame];
168 }
169