File: application.cc

package info (click to toggle)
gnomemm 1.2.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,936 kB
  • ctags: 902
  • sloc: sh: 8,854; cpp: 4,616; perl: 1,220; makefile: 622; ansic: 14
file content (210 lines) | stat: -rw-r--r-- 5,659 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* application.cc
 *
 * Copyright (C) 1999 Havoc Pennington, The Gtk-- Development Team
 *
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include <cstdio>

#include <algorithm>

#include <gnome.h>
#include <libgnome/gnome-i18n.h>
#include <gtk--/menu.h>
#include <gtk--/menubar.h>
#include <gnome--/main.h>
#include <gnome--/about.h>
#include <gnome--/dialog.h>
#include "application.h"


AppExample::AppExample()
: Gnome::App("ExampleApp", "Example App"),
  m_Status(false, true, GNOME_PREFERENCES_NEVER),
  m_Button_Insert("Insert submenu items"),
  m_Button_Disable("Disable Save menu item"),
  m_Button_Enable("Enable Save menu item")
{
  m_pMenuItem = 0;

  init();
  show_all();
}

AppExample::~AppExample()
{
  Gtk::Main::quit();      
}


void
AppExample::init()
{ 
  set_policy(false, true, false);
  set_default_size(250, 350);
  set_wmclass("exampleapp", "ExampleApp");

 
  //Connect signals:
  m_Button_Insert.clicked.connect(slot(this, &AppExample::on_button_insert));
  m_Button_Disable.clicked.connect(slot(this, &AppExample::on_button_disable));
  m_Button_Enable.clicked.connect(slot(this, &AppExample::on_button_enable));

  m_HBox.pack_start(m_Button_Insert, false); 
  m_HBox.pack_start(m_Button_Disable, false); 
  m_HBox.pack_start(m_Button_Enable, false); 
  
  m_VBox.pack_start(m_HBox, false);  
  set_contents(m_VBox);
  m_HBox.show_all();
 

  set_statusbar(m_Status);

  install_menus();
  install_toolbars();
}

void
AppExample::install_menus()
{
  type_vecGnome_UI_SubTree menu_UI_Infos; //whole menu.

  // File menu
  type_vecGnome_UI_Info menu_file; //file menu.

  //Build menu:
  menu_file.push_back(Gnome::UI::SubTree("Sub Menu", type_vecGnome_UI_Info(), "Sub menu items will be inserted here."));
  menu_file.push_back(Gnome::MenuItems::Save(slot(this, &AppExample::on_menu_generic)));
  guint posFileSave = menu_file.size() - 1; //remember for later.

  menu_file.push_back(Gnome::UI::Separator()); 
  menu_file.push_back(Gnome::MenuItems::Exit(slot(this, &AppExample::on_menu_file_exit)));

  //Add menu:
  menu_UI_Infos.push_back(Gnome::Menus::File(menu_file));

  
  //Edit menu
  type_vecGnome_UI_Info menu_edit;

  //Build menu:
  menu_edit.push_back(Gnome::MenuItems::Cut(slot(this, &AppExample::on_menu_generic)));
  menu_edit.push_back(Gnome::MenuItems::Copy(slot(this, &AppExample::on_menu_generic)));
  menu_edit.push_back(Gnome::MenuItems::Paste(slot(this, &AppExample::on_menu_generic)));
  menu_edit.push_back(Gnome::MenuItems::Clear(slot(this, &AppExample::on_menu_generic)));

  //Add menu:
  menu_UI_Infos.push_back(Gnome::Menus::Edit(menu_edit));


  //Create menus and examine the result:
  Gnome::UI::Array<Gnome::UI::SubTree>& arrayInfo = create_menus(menu_UI_Infos);

  //Get created File info:
  Gnome::UI::SubTree& subtreeFile = arrayInfo[0];
  Gnome::UI::Array<Gnome::UI::Info>& arrayInfoFile = subtreeFile.get_uitree(); //vector of menu item Gnome::UI::Info.
  
  //Get created File/Save widget from info:
  m_pMenuItem = arrayInfoFile[posFileSave].get_widget();


  install_menu_hints();
}

void
AppExample::install_toolbars()
{
  type_vecGnome_UI_Info toolbar; 

  toolbar.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_SAVE),
                            N_("Save "),
                            slot(this, &AppExample::on_menu_generic),
                            N_("Save this document")));
  guint posSave = toolbar.size() - 1; //Remember for later.

  toolbar.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_BACK),
                           N_("Prev"),
                           slot(this, &AppExample::on_menu_generic),
                           N_("Previous hello")));
  toolbar.push_back(Gnome::UI::Item(Gnome::UI::Icon(GNOME_STOCK_PIXMAP_FORWARD),
                           N_("Next"),
                           slot(this, &AppExample::on_menu_generic),
                           N_("Next hello")));

  Gnome::UI::Array<Gnome::UI::Info>& arrayInfo = create_toolbar(toolbar);
  m_pToolbarItem = arrayInfo[posSave].get_widget();
}


void       
AppExample::close()
{
  destroy();
}

gint 
AppExample::delete_event_impl(GdkEventAny* e)
{
  return false; 
}


void
AppExample::on_menu_file_exit()
{
  close();
}

void
AppExample::on_menu_generic()
{
  std::cout << "Signal handler called." << std::endl;
}


void
AppExample::on_button_insert()
{
  type_vecGnome_UI_Info vecUI_Info;
  vecUI_Info.push_back(Gnome::UI::Item("Inserted Item", slot(this, &AppExample::on_menu_generic), "Dynamically inserted item."));
  insert_menus("File/Sub Menu/", vecUI_Info);
  
}

void
AppExample::on_button_disable()
{
  if(m_pMenuItem)
    m_pMenuItem->set_sensitive(false);

  if(m_pToolbarItem)
    m_pToolbarItem->set_sensitive(false);
  else
    std::cerr << "AppExample::on_button_disable(): m_pToolbarItem == 0" << std::endl;

}

void
AppExample::on_button_enable()
{
  if(m_pMenuItem)
    m_pMenuItem->set_sensitive(true);

  if(m_pToolbarItem)
    m_pToolbarItem->set_sensitive(true);
}