~ubuntu-branches/ubuntu/precise/gtkmm3.0/precise

« back to all changes in this revision

Viewing changes to gtk/src/bin.ccg

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-17 00:12:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110617001244-9hl5an15hiaaahi6
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
/* $Id: bin.ccg,v 1.2 2004/03/15 00:26:00 murrayc Exp $ */
 
3
 
 
4
/*
 
5
 *
 
6
 * Copyright 1998-2002 The gtkmm Development Team
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 * This library is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with this library; if not, write to the Free
 
20
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 */
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <gtkmm/adjustment.h>
 
25
#include <gtkmm/label.h>
 
26
#include <gtkmm/box.h>
 
27
#include <gtkmm/image.h>
 
28
 
 
29
namespace Gtk
 
30
{
 
31
 
 
32
 
 
33
void
 
34
Bin::remove()
 
35
{
 
36
  GtkWidget* child = gtk_bin_get_child(gobj());
 
37
  if(child)
 
38
  {
 
39
    Gtk::Widget* cppChild = Glib::wrap(child);
 
40
 
 
41
    //If this is a managed widget,
 
42
    //then do an extra ref so that it will
 
43
    //not be destroyed when adding to another container
 
44
    //This should leave it in much the same state as when it was instantiated,
 
45
    //before being added to the first container.
 
46
    if(cppChild->is_managed_())
 
47
      cppChild->reference();
 
48
 
 
49
    gtk_container_remove(Container::gobj(), cppChild->gobj());
 
50
  }
 
51
}
 
52
 
 
53
void
 
54
Bin::add_label(const Glib::ustring& str, bool mnemonic /* = false */,
 
55
                     double x_align /* = 0.5 */, double y_align /* = 0.5 */)
 
56
{
 
57
  Label* label = manage(new Label(str, x_align, y_align, mnemonic));
 
58
  add(*label);
 
59
 
 
60
  //This might not always be appropriate:
 
61
  //because maybe the mnemonic widget should be another child widget.
 
62
  //if(mnemonic)
 
63
    //label->set_mnemonic_widget(*this);
 
64
 
 
65
  label->show();
 
66
}
 
67
 
 
68
void
 
69
Bin::add_label(const Glib::ustring& str, bool mnemonic,
 
70
               Align x_align, Align y_align /* = ALIGN_CENTER */)
 
71
{
 
72
  add_label(str, mnemonic,
 
73
            _gtkmm_align_float_from_enum(x_align),
 
74
            _gtkmm_align_float_from_enum(y_align));
 
75
}
 
76
 
 
77
void
 
78
Bin::add_pixlabel(const std::string& pixfile,
 
79
                  const Glib::ustring& str,
 
80
                  double x_align /* = 0.5 */, double y_align /* = 0.5 */)
 
81
{
 
82
  //Create Image and Label widgets:
 
83
  Image* pmap = manage(new Image(pixfile));
 
84
  Label* label = manage(new Label(str));
 
85
  label->set_alignment (x_align, y_align);
 
86
 
 
87
  //Put them in a Box:
 
88
  Box* hbox = manage(new HBox(false, 5));
 
89
  hbox->pack_start(*pmap, PACK_SHRINK);
 
90
  hbox->pack_start(*label);
 
91
  hbox->show_all();
 
92
 
 
93
  //And put that Box in this:
 
94
  add(*hbox);
 
95
}
 
96
 
 
97
 
 
98
} /* namespace Gtk */