Debian Codegraph @

src/af/xap/xp/xap_FrameImpl.cpp

raw
1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2
3 /* AbiSource Application Framework
4 * Copyright (C) 1998-2000 AbiSource, Inc.
5 * Copyright (C) 2002
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "xap_Frame.h"
28 #include "xap_FrameImpl.h"
29 #include "xap_App.h"
30 #include "xad_Document.h"
31 #include "ut_types.h"
32 #include "ut_vector.h"
33 #include "ut_string.h"
34 #include "ev_Keyboard.h"
35 #include "ev_Mouse.h"
36 #include "ev_Toolbar.h"
37 #include "xap_Prefs.h"
38 #include "ut_assert.h"
39 #include "ut_path.h"
40
41 /*** Also look at xap_Frame.cpp, half the XAP_FrameImpl seems to be there!!! ***/
42
43 XAP_FrameImpl::XAP_FrameImpl(XAP_Frame *pFrame) :
44 m_pMouse(0),
45 m_pKeyboard(0),
46 m_iFrameMode(XAP_NormalFrame),
47 m_ViewAutoUpdaterID(0),
48 m_ViewAutoUpdater(NULL),
49 m_szToolbarLabelSetName(0),
50 m_szToolbarAppearance(0),
51 m_szMenuLayoutName(0),
52 m_szMenuLabelSetName(0),
53 m_pFrame(pFrame)
54 {
55 }
56
57 XAP_FrameImpl::~XAP_FrameImpl(void)
58 {
59 DELETEP(m_pKeyboard);
60 DELETEP(m_pMouse);
61
62 if(m_ViewAutoUpdaterID != 0) {
63 m_ViewAutoUpdater->stop();
64 }
65
66 DELETEP(m_ViewAutoUpdater);
67
68 FREEP(m_szMenuLayoutName);
69 FREEP(m_szMenuLabelSetName);
70
71 UT_VECTOR_FREEALL(char *,m_vecToolbarLayoutNames);
72 FREEP(m_szToolbarLabelSetName);
73 FREEP(m_szToolbarAppearance);
74 UT_VECTOR_PURGEALL(EV_Toolbar *, m_vecToolbars);
75 }
76
77 void XAP_FrameImpl::notifyViewChanged(AV_View * )
78 {
79 // called from XAP_Frame::setView(pView)
80 }
81
82 UT_RGBColor XAP_FrameImpl::getColorSelBackground () const
83 {
84 return UT_RGBColor(192, 192, 192);
85 }
86
87 UT_RGBColor XAP_FrameImpl::getColorSelForeground () const
88 {
89 return UT_RGBColor(255, 255, 255);
90 }
91
92 bool XAP_FrameImpl::_updateTitle()
93 {
94 /*
95 The document title for this window has changed, so we need to:
96
97 1. Update m_szTitle accordingly. (happens here)
98 2. Update the window title. (happens in subclass)
99
100 Note that we don't need to update the contents of the Window menu,
101 because that happens dynamically at menu pop-up time.
102 */
103
104 UT_return_val_if_fail(m_pFrame && m_pFrame->m_pDoc,false);
105
106 const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
107 UT_return_val_if_fail(pSS, false);
108
109 std::string s;
110 UT_GOFilePermissions *perm = NULL;
111 const gchar *szURI = m_pFrame->m_pDoc->getFilename();
112
113 if (szURI && *szURI)
114 perm = UT_go_get_file_permissions(szURI);
115
116 /* first try to use the metadata title as our title */
117 std::string title;
118 if (m_pFrame->m_pDoc->getMetaDataProp ("dc.title", title) && m_pFrame->m_sTitle.size()) {
119 m_pFrame->m_sTitle = title;
120 m_pFrame->m_sNonDecoratedTitle = m_pFrame->m_sTitle;
121
122 if (m_pFrame->m_pDoc->isDirty())
123 m_pFrame->m_sTitle = "*" + m_pFrame->m_sTitle;
124
125 if (perm && !perm->owner_write)
126 {
127 if(pSS->getValueUTF8(XAP_STRING_ID_ReadOnly,s))
128 m_pFrame->m_sTitle += " (" + s + ")";
129 }
130
131 FREEP(perm);
132 return true;
133 }
134 else {
135 m_pFrame->m_sTitle = "";
136 }
137
138 /* that failed. let's use the filename instead */
139
140 if (szURI && *szURI)
141 {
142 gchar *szName = UT_go_basename_from_uri (szURI);
143 UT_UTF8String sUntruncatedString(szName);
144 FREEP(szName);
145
146 int lenRO = 0;
147 if (perm && !perm->owner_write)
148 {
149 if(pSS->getValueUTF8(XAP_STRING_ID_ReadOnly,s))
150 lenRO = s.size();
151 }
152 if (lenRO > MAX_TITLE_LENGTH)
153 {
154 // broken translation file?
155 UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
156 lenRO = 0;
157 }
158
159 // WL_FIXME: we probably need a string truncation function, in the ut_utf8string class..
160 UT_UTF8Stringbuf::UTF8Iterator iter = sUntruncatedString.getIterator ();
161 iter = iter.start ();
162 for (int currentSize = sUntruncatedString.size(); currentSize > (MAX_TITLE_LENGTH - lenRO); currentSize--)
163 iter.advance();
164 m_pFrame->m_sTitle = iter.current();
165
166 if(lenRO > 0)
167 m_pFrame->m_sTitle += " (" + s + ")";
168 }
169 else
170 {
171 UT_ASSERT(m_pFrame->m_iUntitled);
172 pSS->getValueUTF8(XAP_STRING_ID_UntitledDocument,s);
173
174 m_pFrame->m_sTitle = UT_UTF8String_sprintf(m_pFrame->m_sTitle,s.c_str(),m_pFrame->m_iUntitled);
175 }
176
177 m_pFrame->m_sNonDecoratedTitle = m_pFrame->m_sTitle;
178
179 if (m_pFrame->m_nView)
180 {
181 // multiple top-level views, so append : & view number
182 UT_UTF8String sBuf;
183 UT_UTF8String_sprintf(sBuf, ":%d", m_pFrame->m_nView);
184 m_pFrame->m_sTitle += sBuf;
185 }
186
187 // only for non-untitled documents
188 if (m_pFrame->m_pDoc->isDirty())
189 m_pFrame->m_sTitle = "*" + m_pFrame->m_sTitle;
190
191 FREEP(perm);
192 return true;
193 }
194 //#endif