~ubuntu-branches/ubuntu/precise/apvlv/precise-201112121632

« back to all changes in this revision

Viewing changes to src/ApvlvCore.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ritter
  • Date: 2009-09-09 13:13:13 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090909131313-mdp4j7s8r3cqx8rb
Tags: 0.0.7.2-1
* New upstream release
* Improved the long description
* Added patch that fixes a makefile path problem
  (02-fix-path-in-makefile.dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
/* @date Created: 2009/01/04 09:34:51 Alf*/
28
28
 
29
29
#include "ApvlvParams.hpp"
 
30
#include "ApvlvView.hpp"
30
31
#include "ApvlvCore.hpp"
31
32
 
32
33
#include <stdlib.h>
35
36
 
36
37
namespace apvlv
37
38
{
38
 
  ApvlvCore::ApvlvCore ()
39
 
    {
40
 
      mReady = false;
41
 
 
42
 
      mProCmd = 0;
43
 
 
44
 
      mRotatevalue = 0;
45
 
 
46
 
      mResults = NULL;
47
 
      mSearchstr = "";
48
 
 
49
 
      mVbox = gtk_vbox_new (FALSE, 0);
50
 
      g_object_ref (mVbox);
51
 
 
52
 
      mScrollwin = gtk_scrolled_window_new (NULL, NULL);
53
 
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mScrollwin), GTK_POLICY_AUTOMATIC,
54
 
                                      GTK_POLICY_AUTOMATIC);
55
 
 
56
 
      mVaj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (mScrollwin));
57
 
      mHaj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (mScrollwin));
58
 
    }
 
39
  class ApvlvView;
 
40
  extern ApvlvView *gView;
 
41
 
 
42
    ApvlvCore::ApvlvCore ()
 
43
  {
 
44
    mReady = false;
 
45
 
 
46
    mProCmd = 0;
 
47
 
 
48
    mRotatevalue = 0;
 
49
 
 
50
    mResults = NULL;
 
51
    mSearchstr = "";
 
52
 
 
53
    mVbox = gtk_vbox_new (FALSE, 0);
 
54
    g_object_ref (mVbox);
 
55
 
 
56
    mScrollwin = gtk_scrolled_window_new (NULL, NULL);
 
57
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mScrollwin),
 
58
                                    GTK_POLICY_AUTOMATIC,
 
59
                                    GTK_POLICY_AUTOMATIC);
 
60
 
 
61
    mVaj =
 
62
      gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (mScrollwin));
 
63
    mHaj =
 
64
      gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (mScrollwin));
 
65
  }
59
66
 
60
67
  ApvlvCore::~ApvlvCore ()
61
 
    {
62
 
      g_object_unref (mVbox);
63
 
    }
64
 
 
65
 
  void
66
 
    ApvlvCore::inuse (bool use)
67
 
      {
68
 
        mInuse = use;
69
 
      }
70
 
 
71
 
  bool
72
 
    ApvlvCore::inuse ()
73
 
      {
74
 
        return mInuse;
75
 
      }
76
 
 
77
 
  int
78
 
    ApvlvCore::type ()
79
 
      {
80
 
        return mType;
81
 
      }
82
 
 
83
 
  returnType
84
 
    ApvlvCore::process (int ct, guint key)
85
 
      {
86
 
        return MATCH;
87
 
      }
88
 
 
89
 
  void
90
 
    ApvlvCore::setsize (int w, int h)
91
 
      {
92
 
        gtk_widget_set_usize (widget (), w, h);
93
 
        gtk_widget_set_usize (mScrollwin, w, h - 20);
94
 
        mStatus->setsize (w, 20);
95
 
        mWidth = w;
96
 
        mHeight = h;
97
 
      }
98
 
 
99
 
  ApvlvCore *
100
 
    ApvlvCore::copy ()
101
 
      {
102
 
        return NULL;
103
 
      }
104
 
 
105
 
  const char *
106
 
    ApvlvCore::filename () 
107
 
      { 
108
 
        return mReady && mFilestr.length () > 0? mFilestr.c_str (): NULL; 
109
 
      }
110
 
 
111
 
  void 
112
 
    ApvlvCore::zoomin () 
113
 
      { 
114
 
        mZoomrate *= 1.1; 
115
 
        refresh (); 
116
 
      }
117
 
 
118
 
  void 
119
 
    ApvlvCore::zoomout () 
120
 
      { 
121
 
        if (mZoomrate >= 0.5)
122
 
          {
123
 
            mZoomrate /= 1.1; 
124
 
            refresh (); 
125
 
          }
126
 
      }
127
 
 
128
 
  void
129
 
    ApvlvCore::setzoom (const char *z)
130
 
      {
131
 
        if (strcasecmp (z, "normal") == 0)
132
 
          {
133
 
            mZoommode = NORMAL;
134
 
          }
135
 
        if (strcasecmp (z, "fitwidth") == 0)
136
 
          {
137
 
            mZoommode = FITWIDTH;
138
 
          }
139
 
        if (strcasecmp (z, "fitheight") == 0)
140
 
          {
141
 
            mZoommode = FITHEIGHT;
142
 
          }
143
 
        else
144
 
          {
145
 
            double d = atof (z);
146
 
            if (d > 0)
147
 
              {
148
 
                mZoommode = CUSTOM;
149
 
                mZoomrate = d;
150
 
              }
151
 
          }
152
 
 
153
 
        refresh ();
154
 
      }
155
 
 
156
 
  void
157
 
    ApvlvCore::setzoom (double d)
158
 
      {
159
 
        mZoommode = CUSTOM;
160
 
        mZoomrate = d;
161
 
        refresh ();
162
 
      }
163
 
 
164
 
  gint 
165
 
    ApvlvCore::pagenumber ()
166
 
      { 
167
 
        return mPagenum + 1; 
168
 
      }
169
 
 
170
 
  gint 
171
 
    ApvlvCore::getrotate () 
172
 
      { 
173
 
        return mRotatevalue; 
174
 
      }
175
 
 
176
 
  gint 
177
 
    ApvlvCore::pagesum () 
178
 
      { 
179
 
        return 1; 
180
 
      }
181
 
 
182
 
  gdouble 
183
 
    ApvlvCore::zoomvalue () 
184
 
      { 
185
 
        return mZoomrate; 
186
 
      }
187
 
 
188
 
  bool 
189
 
    ApvlvCore::loadfile (const char *file, bool check)
190
 
      {
191
 
        return false;
192
 
      }
193
 
 
194
 
  GtkWidget *
195
 
    ApvlvCore::widget ()
196
 
      {
197
 
        return mVbox;
198
 
      }
199
 
 
200
 
  void
201
 
    ApvlvCore::showpage (gint p, gdouble s)
202
 
      {
203
 
      }
204
 
 
205
 
  void
206
 
    ApvlvCore::refresh ()
207
 
      {
208
 
      }
209
 
 
210
 
  double
211
 
    ApvlvCore::scrollrate ()
212
 
      {
213
 
        double maxv = mVaj->upper - mVaj->lower - mVaj->page_size;
214
 
        double val =  mVaj->value / maxv;
215
 
        if (val > 1.0)
216
 
          {
217
 
            return 1.00;
218
 
          }
219
 
        else if (val > 0.0)
220
 
          {
221
 
            return val;
222
 
          }
223
 
        else
224
 
          {
225
 
            return 0.00;
226
 
          }
227
 
      }
228
 
 
229
 
  gboolean
230
 
    ApvlvCore::scrollto (double s)
231
 
      {
232
 
        if (!mReady)
233
 
          return FALSE;
234
 
 
235
 
        if (mVaj->upper != mVaj->lower)
236
 
          {
237
 
            double maxv = mVaj->upper - mVaj->lower - mVaj->page_size;
238
 
            double val = maxv * s;
239
 
            gtk_adjustment_set_value (mVaj, val);
240
 
            mStatus->show ();
241
 
            return TRUE;
242
 
          }
243
 
        else
244
 
          {
245
 
            debug ("fatal a timer error, try again!");
246
 
            return FALSE;
247
 
          }
248
 
      }
249
 
 
250
 
  void
251
 
    ApvlvCore::scrollup (int times)
252
 
      {
253
 
        if (!mReady)
254
 
          return;
255
 
 
256
 
        gdouble val = gtk_adjustment_get_value (mVaj);
257
 
        gdouble sub = mVaj->upper - mVaj->lower;
258
 
        mVrate = sub / mLines;
259
 
 
260
 
        if (val - mVrate * times > mVaj->lower)
261
 
          {
262
 
            gtk_adjustment_set_value (mVaj, val - mVrate * times);
263
 
          }
264
 
        else if (val > mVaj->lower)
265
 
          {
266
 
            gtk_adjustment_set_value (mVaj, mVaj->lower);
267
 
          }
268
 
        else
269
 
          {
270
 
            if (gParams->valueb ("continuous"))
271
 
              {
272
 
                showpage (mPagenum - 1, mVaj->upper / (2 * sub - mVaj->page_size));
273
 
              }
274
 
            else
275
 
              {
276
 
                showpage (mPagenum - 1, 1.0);
277
 
              }
278
 
          }
279
 
 
280
 
        mStatus->show ();
281
 
      }
282
 
 
283
 
  void
284
 
    ApvlvCore::scrolldown (int times)
285
 
      {
286
 
        if (!mReady)
287
 
          return;
288
 
 
289
 
        gdouble val = gtk_adjustment_get_value (mVaj);
290
 
        gdouble sub = mVaj->upper - mVaj->lower;
291
 
        mVrate = sub / mLines;
292
 
 
293
 
        if (val + mVrate * times + mVaj->page_size < mVaj->upper)
294
 
          {
295
 
            gtk_adjustment_set_value (mVaj, val + mVrate * times);
296
 
          }
297
 
        else if (val + mVaj->page_size < mVaj->upper)
298
 
          {
299
 
            gtk_adjustment_set_value (mVaj, mVaj->upper - mVaj->page_size);
300
 
          }
301
 
        else
302
 
          {
303
 
            if (gParams->valueb ("continuous"))
304
 
              {
305
 
                showpage (mPagenum + 1, (sub - mVaj->page_size) / 2 / sub);
306
 
              }
307
 
            else
308
 
              {
309
 
                showpage (mPagenum + 1, 0.0);
310
 
              }
311
 
          }
312
 
 
313
 
        mStatus->show ();
314
 
      }
315
 
 
316
 
  void
317
 
    ApvlvCore::scrollleft (int times)
318
 
      {
319
 
        if (!mReady)
320
 
          return;
321
 
 
322
 
        mHrate = (mHaj->upper - mHaj->lower) / mChars;
323
 
        gdouble val = mHaj->value - mHrate * times;
324
 
        if (val > mVaj->lower)
325
 
          {
326
 
            gtk_adjustment_set_value (mHaj, val);
327
 
          }
328
 
        else
329
 
          {
330
 
            gtk_adjustment_set_value (mHaj, mHaj->lower);
331
 
          }
332
 
      }
333
 
 
334
 
  void
335
 
    ApvlvCore::scrollright (int times)
336
 
      {
337
 
        if (!mReady)
338
 
          return;
339
 
 
340
 
        mHrate = (mHaj->upper - mHaj->lower) / mChars;
341
 
        gdouble val = mHaj->value + mHrate * times;
342
 
        if (val + mHaj->page_size < mHaj->upper)
343
 
          {
344
 
            gtk_adjustment_set_value (mHaj, val);
345
 
          }
346
 
        else
347
 
          {
348
 
            gtk_adjustment_set_value (mHaj, mHaj->upper - mHaj->page_size);
349
 
          }
350
 
      }
351
 
 
352
 
  void
353
 
    ApvlvCore::setactive (bool act)
354
 
      {
355
 
        mActive = act;
356
 
      }
 
68
  {
 
69
    g_object_unref (mVbox);
 
70
  }
 
71
 
 
72
  void ApvlvCore::inuse (bool use)
 
73
  {
 
74
    mInuse = use;
 
75
 
 
76
    if (mInuse == false && gView->hasloaded (filename (), type ()) == false)
 
77
      {
 
78
        debug ("core :%p is not needed, delete it\n", this);
 
79
        delete this;
 
80
      }
 
81
  }
 
82
 
 
83
  bool ApvlvCore::inuse ()
 
84
  {
 
85
    return mInuse;
 
86
  }
 
87
 
 
88
  int ApvlvCore::type ()
 
89
  {
 
90
    return mType;
 
91
  }
 
92
 
 
93
  returnType ApvlvCore::process (int ct, guint key)
 
94
  {
 
95
    return MATCH;
 
96
  }
 
97
 
 
98
  void ApvlvCore::setsize (int w, int h)
 
99
  {
 
100
    gtk_widget_set_usize (widget (), w, h);
 
101
    gtk_widget_set_usize (mScrollwin, w, h - 20);
 
102
    mStatus->setsize (w, 20);
 
103
    mWidth = w;
 
104
    mHeight = h;
 
105
  }
 
106
 
 
107
  ApvlvCore *ApvlvCore::copy ()
 
108
  {
 
109
    return NULL;
 
110
  }
 
111
 
 
112
  const char *ApvlvCore::filename ()
 
113
  {
 
114
    return mReady && mFilestr.length () > 0 ? mFilestr.c_str () : NULL;
 
115
  }
 
116
 
 
117
  void ApvlvCore::zoomin ()
 
118
  {
 
119
    mZoomrate *= 1.1;
 
120
    refresh ();
 
121
  }
 
122
 
 
123
  void ApvlvCore::zoomout ()
 
124
  {
 
125
    if (mZoomrate >= 0.5)
 
126
      {
 
127
        mZoomrate /= 1.1;
 
128
        refresh ();
 
129
      }
 
130
  }
 
131
 
 
132
  void ApvlvCore::setzoom (const char *z)
 
133
  {
 
134
    if (strcasecmp (z, "normal") == 0)
 
135
      {
 
136
        mZoommode = NORMAL;
 
137
      }
 
138
    if (strcasecmp (z, "fitwidth") == 0)
 
139
      {
 
140
        mZoommode = FITWIDTH;
 
141
      }
 
142
    if (strcasecmp (z, "fitheight") == 0)
 
143
      {
 
144
        mZoommode = FITHEIGHT;
 
145
      }
 
146
    else
 
147
      {
 
148
        double d = atof (z);
 
149
        if (d > 0)
 
150
          {
 
151
            mZoommode = CUSTOM;
 
152
            mZoomrate = d;
 
153
          }
 
154
      }
 
155
 
 
156
    refresh ();
 
157
  }
 
158
 
 
159
  void ApvlvCore::setzoom (double d)
 
160
  {
 
161
    mZoommode = CUSTOM;
 
162
    mZoomrate = d;
 
163
    refresh ();
 
164
  }
 
165
 
 
166
  gint ApvlvCore::pagenumber ()
 
167
  {
 
168
    return mPagenum + 1;
 
169
  }
 
170
 
 
171
  gint ApvlvCore::getrotate ()
 
172
  {
 
173
    return mRotatevalue;
 
174
  }
 
175
 
 
176
  gint ApvlvCore::pagesum ()
 
177
  {
 
178
    return 1;
 
179
  }
 
180
 
 
181
  gdouble ApvlvCore::zoomvalue ()
 
182
  {
 
183
    return mZoomrate;
 
184
  }
 
185
 
 
186
  bool ApvlvCore::loadfile (const char *file, bool check)
 
187
  {
 
188
    return false;
 
189
  }
 
190
 
 
191
  GtkWidget *ApvlvCore::widget ()
 
192
  {
 
193
    return mVbox;
 
194
  }
 
195
 
 
196
  void ApvlvCore::showpage (gint p, gdouble s)
 
197
  {
 
198
  }
 
199
 
 
200
  void ApvlvCore::refresh ()
 
201
  {
 
202
  }
 
203
 
 
204
  double ApvlvCore::scrollrate ()
 
205
  {
 
206
    double maxv = mVaj->upper - mVaj->lower - mVaj->page_size;
 
207
    double val = mVaj->value / maxv;
 
208
    if (val > 1.0)
 
209
      {
 
210
        return 1.00;
 
211
      }
 
212
    else if (val > 0.0)
 
213
      {
 
214
        return val;
 
215
      }
 
216
    else
 
217
      {
 
218
        return 0.00;
 
219
      }
 
220
  }
 
221
 
 
222
  gboolean ApvlvCore::scrollto (double s)
 
223
  {
 
224
    if (!mReady)
 
225
      return FALSE;
 
226
 
 
227
    if (mVaj->upper != mVaj->lower)
 
228
      {
 
229
        double maxv = mVaj->upper - mVaj->lower - mVaj->page_size;
 
230
        double val = maxv * s;
 
231
        gtk_adjustment_set_value (mVaj, val);
 
232
        mStatus->show ();
 
233
        return TRUE;
 
234
      }
 
235
    else
 
236
      {
 
237
        debug ("fatal a timer error, try again!");
 
238
        return FALSE;
 
239
      }
 
240
  }
 
241
 
 
242
  void ApvlvCore::scrollup (int times)
 
243
  {
 
244
    if (!mReady)
 
245
      return;
 
246
 
 
247
    gdouble val = gtk_adjustment_get_value (mVaj);
 
248
    gdouble sub = mVaj->upper - mVaj->lower;
 
249
    mVrate = sub / mLines;
 
250
 
 
251
    if (val - mVrate * times > mVaj->lower)
 
252
      {
 
253
        gtk_adjustment_set_value (mVaj, val - mVrate * times);
 
254
      }
 
255
    else if (val > mVaj->lower)
 
256
      {
 
257
        gtk_adjustment_set_value (mVaj, mVaj->lower);
 
258
      }
 
259
    else
 
260
      {
 
261
        if (gParams->valueb ("autoscrollpage"))
 
262
          {
 
263
            if (gParams->valueb ("continuous"))
 
264
              {
 
265
                showpage (mPagenum - 1,
 
266
                          mVaj->upper / (2 * sub - mVaj->page_size));
 
267
              }
 
268
            else
 
269
              {
 
270
                showpage (mPagenum - 1, 1.0);
 
271
              }
 
272
          }
 
273
      }
 
274
 
 
275
    mStatus->show ();
 
276
  }
 
277
 
 
278
  void ApvlvCore::scrolldown (int times)
 
279
  {
 
280
    if (!mReady)
 
281
      return;
 
282
 
 
283
    gdouble val = gtk_adjustment_get_value (mVaj);
 
284
    gdouble sub = mVaj->upper - mVaj->lower;
 
285
    mVrate = sub / mLines;
 
286
 
 
287
    if (val + mVrate * times + mVaj->page_size < mVaj->upper)
 
288
      {
 
289
        gtk_adjustment_set_value (mVaj, val + mVrate * times);
 
290
      }
 
291
    else if (val + mVaj->page_size < mVaj->upper)
 
292
      {
 
293
        gtk_adjustment_set_value (mVaj, mVaj->upper - mVaj->page_size);
 
294
      }
 
295
    else
 
296
      {
 
297
        if (gParams->valueb ("autoscrollpage"))
 
298
          {
 
299
            if (gParams->valueb ("continuous"))
 
300
              {
 
301
                showpage (mPagenum + 1, (sub - mVaj->page_size) / 2 / sub);
 
302
              }
 
303
            else
 
304
              {
 
305
                showpage (mPagenum + 1, 0.0);
 
306
              }
 
307
          }
 
308
      }
 
309
 
 
310
    mStatus->show ();
 
311
  }
 
312
 
 
313
  void ApvlvCore::scrollleft (int times)
 
314
  {
 
315
    if (!mReady)
 
316
      return;
 
317
 
 
318
    mHrate = (mHaj->upper - mHaj->lower) / mChars;
 
319
    gdouble val = mHaj->value - mHrate * times;
 
320
    if (val > mVaj->lower)
 
321
      {
 
322
        gtk_adjustment_set_value (mHaj, val);
 
323
      }
 
324
    else
 
325
      {
 
326
        gtk_adjustment_set_value (mHaj, mHaj->lower);
 
327
      }
 
328
  }
 
329
 
 
330
  void ApvlvCore::scrollright (int times)
 
331
  {
 
332
    if (!mReady)
 
333
      return;
 
334
 
 
335
    mHrate = (mHaj->upper - mHaj->lower) / mChars;
 
336
    gdouble val = mHaj->value + mHrate * times;
 
337
    if (val + mHaj->page_size < mHaj->upper)
 
338
      {
 
339
        gtk_adjustment_set_value (mHaj, val);
 
340
      }
 
341
    else
 
342
      {
 
343
        gtk_adjustment_set_value (mHaj, mHaj->upper - mHaj->page_size);
 
344
      }
 
345
  }
 
346
 
 
347
  void ApvlvCore::setactive (bool act)
 
348
  {
 
349
    mActive = act;
 
350
 
 
351
    if (mActive && filename () && gView)
 
352
      {
 
353
        gchar *base = g_path_get_basename (filename ());
 
354
        gView->settitle (base);
 
355
        g_free (base);
 
356
      }
 
357
  }
357
358
 
358
359
  ApvlvCoreStatus::ApvlvCoreStatus ()
359
 
    {
360
 
      mHbox = gtk_hbox_new (FALSE, 0);
361
 
    }
 
360
  {
 
361
    mHbox = gtk_hbox_new (FALSE, 0);
 
362
  }
362
363
 
363
364
  ApvlvCoreStatus::~ApvlvCoreStatus ()
364
 
    {
365
 
    }
366
 
 
367
 
  GtkWidget *
368
 
    ApvlvCoreStatus::widget ()
369
 
      {
370
 
        return mHbox;
371
 
      }
372
 
 
373
 
  void
374
 
    ApvlvCoreStatus::active (bool act)
375
 
      {
376
 
      }
377
 
 
378
 
  void
379
 
    ApvlvCoreStatus::setsize (int w, int h)
380
 
      {
381
 
      }
382
 
 
383
 
  void
384
 
    ApvlvCoreStatus::show ()
385
 
      {
386
 
      }
 
365
  {
 
366
  }
 
367
 
 
368
  GtkWidget *ApvlvCoreStatus::widget ()
 
369
  {
 
370
    return mHbox;
 
371
  }
 
372
 
 
373
  void ApvlvCoreStatus::active (bool act)
 
374
  {
 
375
  }
 
376
 
 
377
  void ApvlvCoreStatus::setsize (int w, int h)
 
378
  {
 
379
  }
 
380
 
 
381
  void ApvlvCoreStatus::show ()
 
382
  {
 
383
  }
387
384
}