Project

General

Profile

Download (8.12 KB) Statistics
| Branch: | Tag: | Revision:

aqfinance / src / fox / lib / ff_modulemanager.cpp @ 200398b3

1
/****************************************************************************
2
 * This file is part of the project AqFinance.
3
 * AqFinance (c) by 2007 Martin Preuss, all rights reserved.
4
 *
5
 * The license for this file can be found in the file COPYING which you
6
 * should have received along with this file.
7
 ****************************************************************************/
8

    
9
#ifdef HAVE_CONFIG_H
10
# include <config.h>
11
#endif
12

    
13

    
14
#include "ff_modulemanager.hpp"
15
#include "ff_module.hpp"
16
#include "ff_app.hpp"
17
#include "ff_listitem.hpp"
18

    
19
#include <gwenhywfar/debug.h>
20

    
21

    
22

    
23
FXDEFMAP(FF_ModuleManager) FF_ModuleManagerMap[]= {
24
  FXMAPFUNC(SEL_SELECTED, FF_ModuleManager::ID_LISTBOX, FF_ModuleManager::onListSelected)
25
};
26

    
27

    
28
FXIMPLEMENT(FF_ModuleManager, FXComposite, FF_ModuleManagerMap, ARRAYNUMBER(FF_ModuleManagerMap))
29

    
30

    
31

    
32

    
33
FF_ModuleManager::FF_ModuleManager(FF_App *app,
34
                                   FXComposite *p,
35
                                   FXuint opts)
36
  :FXComposite(p, opts)
37
  , m_app(app)
38
  , m_currentModule(NULL)
39
  , m_splitter(NULL)
40
  , m_listBox(NULL)
41
  , m_switcher(NULL)
42
{
43
  flags|=FLAG_ENABLED | FLAG_SHOWN;
44
  m_splitter=new FXSplitter(this, this,
45
                            ID_SPLITTER,
46
                            LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y);
47
  m_listBox=new FXList(m_splitter,
48
                       this, ID_LISTBOX,
49
                       LAYOUT_FILL_Y |
50
                       ICON_ABOVE_TEXT);
51
  m_switcher=new FXSwitcher(m_splitter,
52
                            LAYOUT_FILL_X | LAYOUT_FILL_Y);
53
}
54

    
55

    
56

    
57
FF_ModuleManager::FF_ModuleManager()
58
  :FXComposite()
59
  , m_app(NULL)
60
  , m_currentModule(NULL)
61
  , m_splitter(NULL)
62
  , m_listBox(NULL)
63
  , m_switcher(NULL)
64
{
65
}
66

    
67

    
68

    
69
FF_ModuleManager::~FF_ModuleManager()
70
{
71
  FF_ModulePtrList::iterator it;
72

    
73
  for (it=m_modules.begin();
74
       it!=m_modules.end();
75
       it++) {
76
    delete (*it);
77
  }
78
  m_modules.clear();
79
}
80

    
81

    
82

    
83
void FF_ModuleManager::create()
84
{
85
  FXComposite::create();
86
  m_splitter->create();
87
  m_listBox->create();
88
  m_switcher->create();
89
}
90

    
91

    
92

    
93
void FF_ModuleManager::init()
94
{
95
  int rv;
96
  int i;
97

    
98
  rv=GWEN_ConfigMgr_GetGroup(AE_GetConfigManager(),
99
                             "modules",
100
                             "main",
101
                             &m_mainConfig);
102
  if (rv<0) {
103
    DBG_ERROR(0, "Error getting main configuration group (%d)", rv);
104
    return;
105
  }
106

    
107
  i=GWEN_DB_GetIntValue(m_mainConfig, "splitterColumn", 0, m_splitter->getSplit(0));
108
  m_splitter->setSplit(0, i);
109

    
110
}
111

    
112

    
113

    
114
void FF_ModuleManager::fini()
115
{
116
  FF_ModulePtrList::iterator it;
117

    
118
  for (it=m_modules.begin();
119
       it!=m_modules.end();
120
       it++) {
121
    (*it)->fini();
122
  }
123

    
124
  if (m_mainConfig) {
125
    int rv;
126

    
127
    rv=GWEN_ConfigMgr_LockGroup(AE_GetConfigManager(),
128
                                "modules",
129
                                "main");
130
    if (rv<0) {
131
      DBG_ERROR(0, "Unable to lock main configuration group (%d)", rv);
132
    }
133
    else {
134
      GWEN_DB_SetIntValue(m_mainConfig, GWEN_DB_FLAGS_OVERWRITE_VARS,
135
                          "splitterColumn", m_splitter->getSplit(0));
136

    
137
      rv=GWEN_ConfigMgr_SetGroup(AE_GetConfigManager(),
138
                                 "modules",
139
                                 "main",
140
                                 m_mainConfig);
141
      if (rv<0) {
142
        DBG_ERROR(0, "Error getting main configuration group (%d)", rv);
143
      }
144

    
145
      rv=GWEN_ConfigMgr_UnlockGroup(AE_GetConfigManager(),
146
                                    "modules",
147
                                    "main");
148
    }
149

    
150
    GWEN_DB_Group_free(m_mainConfig);
151
    m_mainConfig=NULL;
152
  }
153

    
154
}
155

    
156

    
157

    
158
void FF_ModuleManager::addModule(FF_Module *m)
159
{
160
  FXString text;
161
  FXIcon *icon;
162
  FF_ListItem *item;
163
  AE_BOOK *b;
164

    
165
  b=m_app->getBook();
166

    
167
  text=m->getLabel();
168
  icon=m->getIcon();
169

    
170
  item=new FF_ListItem(text, icon, (void *) m);
171
  m->init(m_switcher);
172
  m_modules.push_back(m);
173
  m_listBox->appendItem(item, FALSE);
174
  if (b)
175
    m->dbOpened(b);
176
  if (m_modules.size()==1) {
177
    m_listBox->setCurrentItem(m_modules.size()-1, false);
178
    m_switcher->setCurrent(m_modules.size()-1);
179
    enterModule(m->getId());
180
  }
181
}
182

    
183

    
184

    
185
bool FF_ModuleManager::enterModule(int id)
186
{
187
  FF_ModulePtrList::iterator it;
188
  int i;
189

    
190
  for (it=m_modules.begin(), i=0;
191
       it!=m_modules.end();
192
       it++, i++) {
193
    if ((*it)->getId()==id) {
194
      if (m_currentModule)
195
        m_currentModule->leave();
196
      m_currentModule=(*it);
197
      m_switcher->setCurrent(i);
198
      (*it)->enter();
199
      return true;
200
    }
201
  }
202

    
203
  return false;
204
}
205

    
206

    
207

    
208

    
209
void FF_ModuleManager::signalReset()
210
{
211
  FF_ModulePtrList::iterator it;
212

    
213
  for (it=m_modules.begin();
214
       it!=m_modules.end();
215
       it++) {
216
    (*it)->reset();
217
  }
218
}
219

    
220

    
221

    
222
void FF_ModuleManager::signalDbOpened(AE_BOOK *bk)
223
{
224
  FF_ModulePtrList::iterator it;
225

    
226
  for (it=m_modules.begin();
227
       it!=m_modules.end();
228
       it++) {
229
    (*it)->dbOpened(bk);
230
  }
231
}
232

    
233

    
234

    
235
void FF_ModuleManager::signalDbClosing()
236
{
237
  FF_ModulePtrList::iterator it;
238

    
239
  for (it=m_modules.begin();
240
       it!=m_modules.end();
241
       it++) {
242
    (*it)->dbClosing();
243
  }
244
}
245

    
246

    
247

    
248
void FF_ModuleManager::signalDbClosed()
249
{
250
  FF_ModulePtrList::iterator it;
251

    
252
  for (it=m_modules.begin();
253
       it!=m_modules.end();
254
       it++) {
255
    (*it)->dbClosed();
256
  }
257
}
258

    
259

    
260

    
261
void FF_ModuleManager::signalDbReload(AE_BOOK_TABLE_TYPE tt)
262
{
263
  FF_ModulePtrList::iterator it;
264

    
265
  for (it=m_modules.begin();
266
       it!=m_modules.end();
267
       it++) {
268
    (*it)->dbReload(tt);
269
  }
270
}
271

    
272

    
273

    
274
bool FF_ModuleManager::dbCheckDeleteObject(FXWindow *parent,
275
                                           AE_BOOK_TABLE_TYPE tt,
276
                                           AQDB_ID id)
277
{
278
  FF_ModulePtrList::iterator it;
279

    
280
  for (it=m_modules.begin();
281
       it!=m_modules.end();
282
       it++) {
283
    if (!((*it)->dbCheckDeleteObject(parent, tt, id)))
284
      return false;
285
  }
286

    
287
  return true;
288
}
289

    
290

    
291

    
292
void FF_ModuleManager::signalJobListUpdated()
293
{
294
  FF_ModulePtrList::iterator it;
295

    
296
  for (it=m_modules.begin();
297
       it!=m_modules.end();
298
       it++) {
299
    (*it)->jobListUpdated();
300
  }
301
}
302

    
303

    
304

    
305
void FF_ModuleManager::signalAboutToSendJobs()
306
{
307
  FF_ModulePtrList::iterator it;
308

    
309
  for (it=m_modules.begin();
310
       it!=m_modules.end();
311
       it++) {
312
    (*it)->aboutToSendJobs();
313
  }
314

    
315
}
316

    
317

    
318

    
319
void FF_ModuleManager::addContextMenuEntriesForStatement(FXWindow *parentWindow, FXMenuPane *menuPane, AE_STATEMENT *st)
320
{
321
  FF_ModulePtrList::iterator it;
322

    
323
  for (it=m_modules.begin();
324
       it!=m_modules.end();
325
       it++) {
326
    (*it)->addContextMenuEntriesForStatement(parentWindow, menuPane, st);
327
  }
328
}
329

    
330

    
331

    
332
long FF_ModuleManager::onListSelected(FXObject *, FXSelector, void *ptr)
333
{
334
  FXint idx;
335
  FF_ModulePtrList::iterator it;
336
  FXint i;
337

    
338
  idx=(FXival) ptr;
339
  for (it=m_modules.begin(), i=idx;
340
       it!=m_modules.end();
341
       it++, i--) {
342
    if (i==0) {
343
      if (m_currentModule)
344
        m_currentModule->leave();
345
      m_currentModule=(*it);
346
      m_switcher->setCurrent(idx);
347
      (*it)->enter();
348
      break;
349
    }
350
  }
351

    
352
  return 1;
353
}
354

    
355

    
356

    
357
void FF_ModuleManager::layout()
358
{
359
  m_splitter->position(0, 0, getWidth(), getHeight());
360
  flags&=~FLAG_DIRTY;
361
}
362

    
363

    
364

    
365

    
366
void FF_ModuleManager::dump(int indent)
367
{
368
  int i;
369
  FF_ModulePtrList::iterator it;
370

    
371
  for (i=0; i<indent; i++)
372
    fprintf(stderr, " ");
373
  fprintf(stderr, "FF_ModuleManager: %d/%d %d/%d\n", getX(), getY(), getWidth(), getHeight());
374

    
375
  for (i=0; i<indent+2; i++)
376
    fprintf(stderr, " ");
377
  fprintf(stderr, "FXSplitter: %d/%d %d/%d (%d %d)\n",
378
          m_splitter->getX(), m_splitter->getY(),
379
          m_splitter->getWidth(), m_splitter->getHeight(),
380
          m_splitter->getDefaultWidth(), m_splitter->getDefaultHeight());
381
  for (i=0; i<indent+4; i++)
382
    fprintf(stderr, " ");
383
  fprintf(stderr, "FXList: %d/%d %d/%d (%d %d)\n",
384
          m_listBox->getX(), m_listBox->getY(),
385
          m_listBox->getWidth(), m_listBox->getHeight(),
386
          m_listBox->getDefaultWidth(), m_listBox->getDefaultHeight());
387
  for (i=0; i<indent+4; i++)
388
    fprintf(stderr, " ");
389
  fprintf(stderr, "FXSwitcher: %d/%d %d/%d (%d %d)\n",
390
          m_switcher->getX(), m_switcher->getY(),
391
          m_switcher->getWidth(), m_switcher->getHeight(),
392
          m_switcher->getDefaultWidth(), m_switcher->getDefaultHeight());
393

    
394
  for (it=m_modules.begin();
395
       it!=m_modules.end();
396
       it++) {
397
    (*it)->dump(indent+6);
398
  }
399

    
400
}
401

    
402

    
403

    
404