Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 27

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 6. Miscellaneous Widgets</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="index.html" title="Programming with gtkmm">
<link rel="prev" href="sec-range-example.html" title="Example">
<link rel="next" href="sec-text-entry.html" title="Entry">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 6. Miscellaneous Widgets</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-range-example.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-text-entry.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter" title="Chapter 6. Miscellaneous Widgets">
<div class="titlepage"><div><div><h2 class="title">
<a name="chapter-misc-widgets"></a>Chapter 6. Miscellaneous Widgets</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul>
<li><span class="sect1"><a href="chapter-misc-widgets.html#sec-labels">Label</a></span></li>
<li><span class="sect1"><a href="sec-text-entry.html">Entry</a></span></li>
<li><span class="sect1"><a href="sec-spinbutton.html">SpinButton</a></span></li>
<li><span class="sect1"><a href="sec-progressbar.html">ProgressBar</a></span></li>
<li><span class="sect1"><a href="sec-infobar.html">InfoBar</a></span></li>
<li><span class="sect1"><a href="sec-tooltips.html">Tooltips</a></span></li>
</ul>
</div>
<div class="sect1" title="Label">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-labels"></a>Label</h2></div></div></div>
<p>
Labels are the  main method of placing non-editable text in windows, for
instance to place a title next to a <code class="classname">Entry</code> widget. You
can specify the text in the constructor, or with the
<code class="methodname">set_text()</code> method.
</p>
<p>
The width of the label will be adjusted automatically.  You can produce multi-line labels by putting line breaks ("\n") in the label string.
</p>
<p>
The label text can be justified using the <code class="methodname">set_justify()</code>
method. The widget is also capable of word-wrapping - this can be activated
with <code class="methodname">set_line_wrap()</code>.
</p>
<p>
TODO: gtkmm2: markup.
</p>
<p><a class="ulink" href="http://library.gnome.org/devel/gtkmm/unstable/classGtk_1_1Label.html" target="_top">Reference</a></p>
<div class="sect2" title="Example">
<div class="titlepage"><div><div><h3 class="title">
<a name="label-example"></a>Example</h3></div></div></div>
<p>
Below is a short example to illustrate these functions. This example
makes use of the Frame widget to better demonstrate the label styles.
 (The Frame widget is explained in the <a class="link" href="chapter-container-widgets.html#sec-frame" title="Frame">Frame</a> section.)
</p>
<div class="figure">
<a name="figure-label"></a><p class="title"><b>Figure 6.1. Label</b></p>
<div class="figure-contents"><div class="screenshot"><div><img src="figures/label.png" alt="Label"></div></div></div>
</div>
<br class="figure-break"><p><a class="ulink" href="http://git.gnome.org/cgit/gtkmm-documentation/tree/examples/book/label" target="_top">Source Code</a></p>
<p>File: <code class="filename">examplewindow.h</code>
</p>
<pre class="programlisting">
#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include &lt;gtkmm.h&gt;

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::HBox m_HBox;
  Gtk::VBox m_VBox, m_VBox2;
  Gtk::Frame m_Frame_Normal, m_Frame_Multi, m_Frame_Left, m_Frame_Right,
    m_Frame_LineWrapped, m_Frame_FilledWrapped, m_Frame_Underlined;
  Gtk::Label m_Label_Normal, m_Label_Multi, m_Label_Left, m_Label_Right,
    m_Label_LineWrapped, m_Label_FilledWrapped, m_Label_Underlined;
};

#endif //GTKMM_EXAMPLEWINDOW_H
</pre>
<p>File: <code class="filename">examplewindow.cc</code>
</p>
<pre class="programlisting">
#include "examplewindow.h"
#include &lt;iostream&gt;

ExampleWindow::ExampleWindow()
:
  m_HBox(false, 5),
  m_VBox(false, 5),
  m_Frame_Normal("Normal Label"),
  m_Frame_Multi("Multi-line Label"),
  m_Frame_Left("Left Justified Label"),
  m_Frame_Right("Right Justified Label"),
  m_Frame_LineWrapped("Line wrapped label"),
  m_Frame_FilledWrapped("Filled, wrapped label"),
  m_Frame_Underlined("Underlined label"),
  m_Label_Normal("_This is a Normal label", true),
  m_Label_Multi("This is a Multi-line label.\nSecond line\nThird line"),
  m_Label_Left("This is a Left-Justified\nMulti-line label.\nThird line"),
  m_Label_Right("This is a Right-Justified\n"
          "Multi-line label.\nFourth line, (j/k)"),
  m_Label_Underlined("This label is underlined!\n"
          "This one is underlined in quite a funky fashion")
{
  set_title("Label");
  set_border_width(5);

  add(m_HBox);

  m_HBox.pack_start(m_VBox, Gtk::PACK_SHRINK);

  m_Frame_Normal.add(m_Label_Normal);
  m_VBox.pack_start(m_Frame_Normal, Gtk::PACK_SHRINK);

  m_Frame_Multi.add(m_Label_Multi);
  m_VBox.pack_start(m_Frame_Multi, Gtk::PACK_SHRINK);

  m_Label_Left.set_justify(Gtk::JUSTIFY_LEFT);
  m_Frame_Left.add(m_Label_Left);
  m_VBox.pack_start(m_Frame_Left, Gtk::PACK_SHRINK);

  m_Label_Right.set_justify(Gtk::JUSTIFY_RIGHT);
  m_Frame_Right.add(m_Label_Right);
  m_VBox.pack_start(m_Frame_Right, Gtk::PACK_SHRINK);

  m_HBox.pack_start(m_VBox2, Gtk::PACK_SHRINK);

  m_Label_LineWrapped.set_text(
          "This is an example of a line-wrapped label.  It " \
          /* add a big space to the next line to test spacing */ \
          "should not be taking up the entire             "
          "width allocated to it, but automatically " \
          "wraps the words to fit.  " \
          "The time has come, for all good men, to come to " \
          "the aid of their party.  " \
          "The sixth sheik's six sheep's sick.\n" \
          "     It supports multiple paragraphs correctly, " \
          "and  correctly   adds " \
          "many          extra  spaces. ");
  m_Label_LineWrapped.set_line_wrap();
  m_Frame_LineWrapped.add(m_Label_LineWrapped);
  m_VBox2.pack_start(m_Frame_LineWrapped, Gtk::PACK_SHRINK);

  m_Label_FilledWrapped.set_text(
          "This is an example of a line-wrapped, filled label.  " \
          "It should be taking " \
          "up the entire              width allocated to it.  " \
          "Here is a sentence to prove " \
          "my point.  Here is another sentence. " \
          "Here comes the sun, do de do de do.\n" \
          "    This is a new paragraph.\n" \
          "    This is another newer, longer, better " \
          "paragraph.  It is coming to an end, " \
          "unfortunately.");
  m_Label_FilledWrapped.set_justify(Gtk::JUSTIFY_FILL);
  m_Label_FilledWrapped.set_line_wrap();
  m_Frame_FilledWrapped.add(m_Label_FilledWrapped);
  m_VBox2.pack_start(m_Frame_FilledWrapped, Gtk::PACK_SHRINK);

  m_Label_Underlined.set_justify(Gtk::JUSTIFY_LEFT);
  m_Label_Underlined.set_pattern (
          "_________________________ _ _________ _ ______"
          "     __ _______ ___");
  m_Frame_Underlined.add(m_Label_Underlined);
  m_VBox2.pack_start(m_Frame_Underlined, Gtk::PACK_SHRINK);

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}
</pre>
<p>File: <code class="filename">main.cc</code>
</p>
<pre class="programlisting">
#include &lt;gtkmm/main.h&gt;
#include "examplewindow.h"

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  ExampleWindow window;
  //Shows the window and returns when it is closed.
  Gtk::Main::run(window);

  return 0;
}
</pre>
</div>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-range-example.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-text-entry.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Example </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Entry</td>
</tr>
</table>
</div>
</body>
</html>