Layout problems using Frames





Hi Guys,

attached is a (Gtk--) program which starts to fill a dialog window
with a bunch of stuff, including a preview. I have added
this preview (d_preview) to a frame (d_previewFrame), but the
frame insists on filling the frame it is in turn part off.
How can I get the preview frame to hug the preview tightly?
All the interesting code for this is in insertPreview().

Thanks a lot
--> Robert

------------------------- cut here ------------------------
#ifndef _GUI_DIALOG_PREVIEW_H
#define _GUI_DIALOG_PREVIEW_H


#include <gtk--.h>
#include <gtk/gtk.h>


class GuiDialogPreview : public Gtk_Dialog
     {
     public:
                         GuiDialogPreview (char *winTitle, char *frameTitle,
                                     int tableX, int tableY);
                         ~GuiDialogPreview ();
          virtual void        buildDialogWindow ();

     protected:
          void           insertPreview ();
          void           clearPreview ();
          void           setupVBox ();
          virtual void        fillVBox ();
          virtual void        fillActionArea ();
          virtual void        buttonCallbackOK ();
          virtual void        buttonCallbackApply ();
          virtual void        buttonCallbackCancel ();
          virtual void        checkboxCallbackPreview ();
          virtual gint        delete_event_impl (GdkEventAny *);

          int            d_size,
                         d_frameBorder;
          Gtk_VBox       d_vBoxPreview;
          Gtk_Button          d_btnOK,
                         d_btnApply,
                         d_btnCancel;
          Gtk_CheckButton          d_cbUsePreview;
          Gtk_Frame      *d_baseFrame,
                         *d_previewFrame,
                         *d_optionsFrame,
                         *d_previewGroupFrame;
          Gtk_Preview         *d_preview;
          Gtk_Table      *d_table;
          char           *d_winTitle,
                         *d_frameTitle;
     };


#endif // _GUI_DIALOG_PREVIEW_H


GuiDialogPreview::GuiDialogPreview (char *winTitle, char *frameTitle,
                        int tableX, int tableY) :
            d_vBoxPreview (FALSE, 0),
            d_btnOK ("OK"),
            d_btnApply ("Apply"),
            d_btnCancel ("Cancel"),
            d_cbUsePreview ("Use Preview")
{
     if (winTitle)
          d_winTitle = strdup (winTitle);
     else
          d_winTitle = strdup ("GuiDialogOAC Window");

     d_frameTitle = strdup (frameTitle);      // required

     d_baseFrame = d_previewFrame = d_optionsFrame =
          d_previewGroupFrame = NULL;
     d_preview = NULL;
     d_size = 100;
     d_frameBorder = 4;

     d_table = new Gtk_Table (tableX, tableY, FALSE);

        this->set_position (GTK_WIN_POS_MOUSE);
}


GuiDialogPreview::~GuiDialogPreview ()
{
     if (d_winTitle) free (d_winTitle);  // c-type alloc from strdup
     if (d_frameTitle) free (d_frameTitle);   // c-type alloc from strdup
     if (d_baseFrame) delete d_baseFrame;
     if (d_previewFrame) delete d_previewFrame;
     if (d_preview) delete d_preview;
     if (d_table) delete d_table;
}


/*
 *  buildDialogWindow:
 */
void GuiDialogPreview::buildDialogWindow ()
{
     this->set_usize (400, 225);
     this->set_title (d_winTitle);

     this->get_vbox()->set_border_width (2);

     setupVBox ();
     insertPreview ();
     fillVBox ();
     fillActionArea ();

     d_baseFrame->show ();
     this->show ();
}


/*
 *  setupVBox: setup the basic frame of the vbox
 */
void GuiDialogPreview::setupVBox ()
{
     d_baseFrame = new Gtk_Frame (d_frameTitle);
     d_baseFrame->set_shadow_type (GTK_SHADOW_ETCHED_IN);
     d_baseFrame->set_border_width (0);
     this->get_vbox()->pack_start (*d_baseFrame, TRUE, TRUE, 0);
     d_baseFrame->show ();
     this->get_vbox()->show ();
}


/*
 *  insertPreview: insert the preview into the main frame/vbox
 */
void GuiDialogPreview::insertPreview ()
{
     // d_hBoxList is the box everything else is inserted into
     d_baseFrame->add (*d_table);

     // build Frame and add it to view
     d_previewFrame = new Gtk_Frame ();
     d_previewFrame->set_shadow_type (GTK_SHADOW_ETCHED_IN);
     d_previewFrame->set_border_width (2);
     d_preview = new Gtk_Preview (GTK_PREVIEW_COLOR);
     d_preview->size (d_size, d_size);
     d_previewFrame->add (*d_preview);
     d_vBoxPreview.pack_start (*d_previewFrame, FALSE, FALSE, 0);

     // setup checkbutton
     d_cbUsePreview.set_active (TRUE);
     connect_to_method (d_cbUsePreview.clicked, this, &checkboxCallbackPreview);
     d_vBoxPreview.pack_start (d_cbUsePreview, FALSE, FALSE, 0);
     d_cbUsePreview.show ();

     // add vbox to bounding Frame
     d_previewGroupFrame = new Gtk_Frame ("Preview");
     d_previewGroupFrame->set_border_width (d_frameBorder);
     d_previewGroupFrame->add (d_vBoxPreview);

     // add everything together and show it
     d_table->attach (*d_previewGroupFrame, 1, 2, 1, 4);

     // second frame
     d_optionsFrame = new Gtk_Frame ();
     d_optionsFrame->set_shadow_type (GTK_SHADOW_ETCHED_IN);
     d_optionsFrame->set_border_width (2);
     d_table->attach (*d_optionsFrame, 3, 6, 1, 3);
     d_optionsFrame->show ();

     d_preview->show ();
     d_previewFrame->show ();
     d_vBoxPreview.show ();
     d_previewGroupFrame->show ();
     d_table->show ();

     clearPreview ();
}


void GuiDialogPreview::clearPreview ()
{
     guchar    *row = new unsigned char [3*d_size];

     for (int i=0; i<d_size; i++)
        for (int j=0; j<d_size; j++)
          {
          row[j*3]=(int) (255.0/d_size*i);
          row[j*3+1]=(int) (255.0/d_size*i);
          row[j*3+2]=(int) (255.0/d_size*i);
          d_preview->draw_row (row, 0, i, d_size);
          }

     delete [] row;
}


/*
 *  fillVBox: fill the previously set-up vbox which remains to be filled
 */
void GuiDialogPreview::fillVBox ()
{
}


/*
 *  fillActionArea: fill the dialog's action area
 */
void GuiDialogPreview::fillActionArea ()
{
     connect_to_method (d_btnOK.clicked, this, &buttonCallbackOK);
     this->get_action_area()->pack_start (d_btnOK, TRUE, TRUE, 0);
     d_btnOK.show ();

     connect_to_method (d_btnApply.clicked, this, &buttonCallbackApply);
     this->get_action_area()->pack_start (d_btnApply, TRUE, TRUE, 0);
     d_btnApply.show ();

     connect_to_method (d_btnCancel.clicked, this, &buttonCallbackCancel);
     this->get_action_area()->pack_start (d_btnCancel, TRUE, TRUE, 0);
     d_btnCancel.show ();
}


void GuiDialogPreview::buttonCallbackOK ()
{
     cout << "GuiDialogPreview: Default Callback OK\n";
}


void GuiDialogPreview::buttonCallbackApply ()
{
     cout << "GuiDialogPreview: Default Callback Apply\n";
}


void GuiDialogPreview::buttonCallbackCancel ()
{
     this->hide ();
}


void GuiDialogPreview::checkboxCallbackPreview ()
{
     if (!d_cbUsePreview.get_active())
          {
          d_preview->set_sensitive (FALSE);
          d_previewFrame->set_sensitive (FALSE);
          }
     else
          {
          d_preview->set_sensitive (TRUE);
          d_previewFrame->set_sensitive (TRUE);
          }
}


gint GuiDialogPreview::delete_event_impl (GdkEventAny *)
{
     this->hide ();
     return (0);
}


int main (int argc, char *argv[])
{
     Gtk_Main  gtkMain (&argc, &argv);
     GuiDialogPreview *testDialog;

     testDialog = new GuiDialogPreview ("Default Title",
          "Default Message", 6, 4);
     testDialog->buildDialogWindow ();
     testDialog->show ();
     gtkMain.run ();
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]