CVR-Lib last update 20 Sep 2009

cvrViewerBaseGtk.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 
00042 /**
00043  * \file    cvrViewerBaseGtk.h
00044  *          This is a "private" file.  It contains GTK specific stuff for
00045  *          implementing the viewerBase class.  Unless you are implementing
00046  *          GTK derived classes, you don't need to include this file.  See
00047  *          cvrViewerBase.h instead.
00048  * \authors Pablo Alvarado
00049  * \date    05.07.2005
00050  *
00051  * $Id: cvrViewerBaseGtk.h,v 1.2 2006/01/18 03:48:35 alvarado Exp $
00052  */
00053 
00054 #ifndef _CVR_VIEWER_BASE_GTK_H_
00055 #define _CVR_VIEWER_BASE_GTK_H_
00056 
00057 #include "cvrViewerBase.h"
00058 
00059 #ifdef HAVE_GTK
00060 
00061 #include "cvrRectangle.h"
00062 #include <gtk/gtk.h>
00063 
00064 namespace cvr {
00065 
00066   // ------------------------------------------------------------------------
00067   //   GTK Toolkit class
00068   // ------------------------------------------------------------------------
00069   // For GTK, which is C, this class is simply a container of static functions
00070   // which are used as slots for all activity
00071 
00072   /**
00073    * GTK toolkit class
00074    *
00075    * This is the parent class for the viewer windows implemented with
00076    * GTK.
00077    * The class initializes the drawing widget, status bar, and scroll bars.
00078    */
00079   class viewerBase::mainWindow::tk {
00080   public:
00081     /**
00082      * Constructor.
00083      *
00084      * This constructor does not call build(), so the main window still has to
00085      * be created.
00086      */
00087     tk(viewerBase::mainWindow& parent);
00088 
00089     /**
00090      * Destructor
00091      */
00092     virtual ~tk();
00093 
00094     /**
00095      * Create window
00096      */
00097     virtual bool build();
00098 
00099     /**
00100      * Show the window
00101      */
00102     virtual bool show();
00103 
00104     /**
00105      * Hide this window
00106      */
00107     virtual bool hide();
00108 
00109     /**
00110      * Destroy window
00111      */
00112     virtual bool destroy();
00113 
00114     /**
00115      * Display in the status bar the given text
00116      */
00117     virtual bool statusBar(const std::string& txt);
00118 
00119     /**
00120      * Copy another mainWindow toolkit configuration
00121      */
00122     tk& copy(const tk& other);
00123 
00124     /**
00125      * Change position of the window
00126      */
00127     virtual bool setPosition(const ipoint& p);
00128 
00129     /**
00130      * Get position of the window
00131      */
00132     ipoint getPosition() const;
00133 
00134     /**
00135      * Set size of the window
00136      */
00137     virtual bool setSize(const ipoint& p);
00138 
00139     /**
00140      * Get size of the window
00141      */
00142     ipoint getSize() const;
00143 
00144     /**
00145      * Get initial suggestion for window size
00146      */
00147     virtual ipoint suggestWindowSize() const;
00148 
00149     /**
00150      * Set window title
00151      */
00152     virtual bool setTitle(const std::string& title);
00153 
00154     /**
00155      * Get a string with the title of this window
00156      */
00157     std::string getTitle() const;
00158 
00159     /**
00160      * Update parameters.
00161      */
00162     virtual bool updateParameters(viewerBase::parameters& param);
00163 
00164     /**
00165      * Resize canvas
00166      */
00167     virtual bool setCanvasSize(const ipoint& newSize);
00168 
00169   protected:
00170     /**
00171      * Pointer to a read-only version of the parameters
00172      */
00173     viewerBase::parameters* params_;
00174 
00175     /**
00176      * Pointer to the class that owns this instance.
00177      */
00178     viewerBase::mainWindow* parent_;
00179 
00180     /**
00181      * Flag that indicates if the window is currently being shown
00182      */
00183     bool winShown_;
00184 
00185     /**
00186      * Flag that indicates if the window is currently being shown
00187      */
00188     bool winBuild_;
00189 
00190     /*
00191      * Border offset
00192      *
00193      * The user always indicates the size of the drawing area, without
00194      * considering the borders which may be style/theme dependent.
00195      *
00196      * This value is set automatically when the user interacts with the
00197      * window, which is the first time.
00198      *
00199      * It is initialized with negative values to indicate that the value has
00200      * to be updated as soon as reliable information is available (ie. the
00201      * viewer has been displayed)
00202      */
00203     ipoint borderOffset_;
00204 
00205     /**
00206      * The main window.
00207      *
00208      * In GTK a window widget should be a pop up menu or the top window
00209      * application.  It is therefore more appropriate to use the gtk_dialog
00210      * to hold the images, as they have less restrictions and are easier to
00211      * manipulate.
00212      */
00213     GtkWidget* window_;
00214 
00215     /**
00216      * Vertical box for packing two components: the drawing area and the status
00217      * bar
00218      */
00219     GtkWidget* vbox_;
00220 
00221     /**
00222      * The scrolled window.
00223      */
00224     GtkWidget *scrolledWindow_;
00225 
00226     /**
00227      * The status bar.
00228      */
00229     GtkWidget *statusBar_;
00230 
00231     /**
00232      * Context id of the status bar.
00233      */
00234     guint statusBarContextId_;
00235 
00236     /**
00237      * Drawing area that holds the image.
00238      */
00239     GtkWidget *drawingArea_;
00240 
00241     /**
00242      * Event box to capture mouse and button events.
00243      */
00244     GtkWidget *eventBox_;
00245 
00246     GdkCursor* cursor_;
00247 
00248     /**
00249      * Protect all members from multiple access
00250      */
00251     mutex lock_;
00252 
00253     /**
00254      * Static functions used by GTK as callbacks and their corresponding
00255      * local versions.
00256      *
00257      * Even if the CVR-Lib forbids the use of prefixes, here an exception
00258      * has been done with "cb", meaning "callback", which is used to keep
00259      * a direct correspondence between the GTK required static function and
00260      * a local instance-bounded virtual method.
00261      */
00262     //@{
00263 
00264     /**
00265      * Callback function called when the user has explicitelly indicated
00266      * a show()
00267      */
00268     static gboolean cbShow(gpointer data);
00269 
00270     /**
00271      * Callback function called when the user selects the "close window"
00272      * button of the window.  This method overrides the delete structure with
00273      * a hide().
00274      */
00275     static gint cbCloseWindow(GtkWidget *widget,
00276                               GdkEvent  *event,
00277                               gpointer   data);
00278 
00279     /**
00280      * Close the window and all related elements
00281      */
00282     virtual bool closeWindow();
00283 
00284     /**
00285      * Callback fuction called when the window size or position have been
00286      * changed.
00287      */
00288     static gint cbGeometryChanged(GtkWidget*        widget,
00289                                  GdkEventConfigure* event,
00290                                  gpointer           data);
00291 
00292     /**
00293      * Called when the geometry of the window is changed.
00294      *
00295      * Note that this won't change the geometry, since it is called by
00296      * someone who changed it already.
00297      */
00298     virtual bool geometryChanged(const ipoint pos,
00299                                  const ipoint size);
00300 
00301     /**
00302      * Callback funtion to redraw the image been displayed.
00303      */
00304     static gint cbDrawingAreaExposed(GtkWidget*      widget,
00305                                      GdkEventExpose* event,
00306                                      gpointer        data);
00307 
00308     /**
00309      * Called when some part of the window has been exposed and need to be
00310      * redrawn.
00311      */
00312     virtual bool drawingAreaExposed(const irectangle& area);
00313 
00314     /**
00315      * Callback function called when the mouse is moved while a mouse
00316      * button is been pressed.
00317      */
00318     static gint cbMouseMoved(GtkWidget*      widget,
00319                              GdkEventMotion* event,
00320                              gpointer        data);
00321 
00322     /**
00323      * Function called when the mouse has been moved and some button is pressed
00324      */
00325     bool mouseMoved(const viewerBase::interaction action,
00326                     const ipoint pos);
00327 
00328     /**
00329      * Callback function called when any mouse button has been pressed.
00330      */
00331     static gint cbButtonPressed(GtkWidget*      widget,
00332                                 GdkEventButton* event,
00333                                 gpointer        data);
00334 
00335     /**
00336      * Function called when a mouse button has been pressed
00337      */
00338     bool buttonPressed(const viewerBase::interaction action,
00339                        const ipoint pos);
00340 
00341     /**
00342      * Callback function called when any mouse button has been pressed.
00343      */
00344     static gint cbScrolled(GtkWidget*      widget,
00345                            GdkEventScroll* event,
00346                            gpointer        data);
00347 
00348     /**
00349      * Function called when a mouse button has been pressed
00350      */
00351     bool scrolled(const viewerBase::interaction action,
00352                   const ipoint pos);
00353 
00354     /**
00355      * Callback function called when any mouse button has been pressed.
00356      */
00357     static gint cbButtonReleased(GtkWidget*      widget,
00358                                  GdkEventButton* event,
00359                                  gpointer        data);
00360 
00361     /**
00362      * Function called when a mouse button has been released
00363      */
00364     bool buttonReleased(const viewerBase::interaction action,
00365                         const ipoint pos);
00366 
00367     /**
00368      * Callback function called when any key has been pressed.
00369      */
00370     static gint cbKeyPressed(GtkWidget*   widget,
00371                              GdkEventKey* event,
00372                              gpointer     data);
00373     /**
00374      * Function called when a key has been pressed
00375      */
00376     bool keyPressed(const viewerBase::interaction action);
00377 
00378     /**
00379      * Callback function called when any key has been released.
00380      */
00381     static gint cbKeyReleased(GtkWidget*   widget,
00382                               GdkEventKey* event,
00383                               gpointer     data);
00384 
00385     /**
00386      * Function called when a key has been released
00387      */
00388     bool keyReleased(const viewerBase::interaction action);
00389 
00390     /**
00391      * Callback function used to force a expose event of the whole window.
00392      */
00393     static gboolean cbForceRedraw(gpointer data);
00394 
00395     /**
00396      * This function can be called by either thread, and it will ensure that
00397      * an expose event of the whole window is generated.
00398      */
00399     bool forceRedraw();
00400     //@}
00401   };
00402 
00403   /**
00404    * Private class of the configuration dialogs which deals with
00405    * all internal issues of the GTK toolkit.
00406    */
00407   class viewerBase::configDialog::tk {
00408   public:
00409     /**
00410      * Constructor.
00411      *
00412      * This constructor does not call build(), since at creation time GTK
00413      * may not be initialized yet.
00414      */
00415     tk(viewerBase::configDialog& parent);
00416 
00417     /**
00418      * Destructor
00419      */
00420     virtual ~tk();
00421 
00422     /**
00423      * Create window
00424      */
00425     virtual bool build();
00426 
00427     /**
00428      * Show the window
00429      */
00430     virtual bool show();
00431 
00432     /**
00433      * Hide this window
00434      */
00435     virtual bool hide();
00436 
00437     /**
00438      * Destroy window
00439      */
00440     virtual bool destroy();
00441 
00442     /**
00443      * Copy another mainWindow toolkit configuration
00444      */
00445     tk& copy(const tk& other);
00446 
00447     /**
00448      * Update parameters.
00449      *
00450      * Since the base class has no attributes, this method does nothing but
00451      * to establish the virtual interface.
00452      *
00453      * Since the params_ attribute of the class is just an alias for the ones
00454      * in the enclosing configDialog class, no pointer needs to be
00455      * adjusted.
00456      */
00457     virtual bool updateParameters();
00458 
00459 
00460   protected:
00461     /**
00462      * Reference to the class that owns this instance.
00463      */
00464     viewerBase::configDialog& parent_;
00465 
00466     /**
00467      * Pointer to a read-writable version of the parameters.
00468      *
00469      * It is a reference to the parameters pointer in the configDialog
00470      * enclosing class, initialized at construction time.  This avoids
00471      * inconsistencies between the objects being used.
00472      */
00473     viewerBase::parameters*& params_;
00474 
00475     /**
00476      * Flag that indicates if the window is currently being shown
00477      */
00478     bool dlgShown_;
00479 
00480     /**
00481      * Flag that indicates if the window is currently being shown
00482      */
00483     bool dlgBuild_;
00484 
00485     /**
00486      * The main window.
00487      *
00488      * In GTK a window widget should be a pop up menu or the top window
00489      * application.  It is therefore more appropriate to use the gtk_dialog
00490      * to hold the images, as they have less restrictions and are easier to
00491      * manipulate.
00492      */
00493     GtkWidget* dialog_;
00494 
00495     /**
00496      * Vertical box for packing all components in inherited classes
00497      */
00498     GtkWidget* vbox_;
00499 
00500     /**
00501      * Action area
00502      */
00503     GtkWidget *actionArea_;
00504 
00505     /**
00506      * Cancel button
00507      */
00508     GtkWidget *cancelButton_;
00509 
00510     /**
00511      * Apply button
00512      */
00513     GtkWidget *applyButton_;
00514 
00515     /**
00516      * Ok button
00517      */
00518     GtkWidget *okButton_;
00519 
00520     /**
00521      * Protect all members from multiple access
00522      */
00523     mutex lock_;
00524 
00525     /**
00526      * Static functions used by GTK as callbacks and their corresponding
00527      * local versions.
00528      *
00529      * Even if the CVR-Lib forbids the use of prefixes, here an exception
00530      * has been done with "cb", meaning "callback", which is used to keep
00531      * a direct correspondence between the GTK required static function and
00532      * a local instance-bounded virtual method.
00533      */
00534     //@{
00535     /**
00536      * Callback function called when the user has explicitelly indicated
00537      * a show()
00538      */
00539     static gboolean cbShow(gpointer data);
00540 
00541     /**
00542      * Callback function called when the user selects the "close window"
00543      * button of the window.  This method overrides the delete structure with
00544      * a hide().
00545      */
00546     static gint cbCloseWindow(GtkWidget *widget,
00547                               GdkEvent  *event,
00548                               gpointer   data);
00549 
00550     /**
00551      * Callback function called when the user has pressed the cancel button
00552      */
00553     static void cbOnCancelButtonClicked(GtkButton* button,
00554                                         gpointer data);
00555 
00556     /**
00557      * On apply button
00558      */
00559     virtual bool onCancelButtonClicked();
00560 
00561     /**
00562      * Callback function called when the user has pressed the apply button
00563      */
00564     static void cbOnApplyButtonClicked(GtkButton* button,
00565                                        gpointer data);
00566 
00567     /**
00568      * On apply button
00569      */
00570     virtual bool onApplyButtonClicked();
00571 
00572     /**
00573      * Callback function called when the user has pressed the ok button
00574      */
00575     static void cbOnOkButtonClicked(GtkButton* button,
00576                                     gpointer data);
00577 
00578     /**
00579      * On ok button
00580      */
00581     virtual bool onOkButtonClicked();
00582 
00583     //@}
00584   };
00585 
00586 
00587 }
00588 
00589 #endif
00590 #endif

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8