From 8c4de4ae3a5bcfae336564bd28cbfe5b18caa0cf Mon Sep 17 00:00:00 2001 From: mishas Date: Thu, 17 Jan 2008 21:51:49 +0000 Subject: [PATCH] * added myValidItems member to reflect the number of items to show :) * implemented getWidth, getHeight, getBackgroundColour methods * re-wrote updateWidget method using newly created getWidth/getHeight git-svn-id: file:///svnroot/simple-launcher/branches/new-items@259 3ba93dab-e023-0410-b42a-de7732cf370a --- simple-launcher.cc | 33 +++++++++++++++++++++++---------- simple-launcher.h | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/simple-launcher.cc b/simple-launcher.cc index 6001d30..4156691 100644 --- a/simple-launcher.cc +++ b/simple-launcher.cc @@ -67,7 +67,7 @@ char *SimpleLauncherApplet::ourDirs[] = { }; // SimpleLauncherApplet::SimpleLauncherApplet() : myMainSettings(myClient.getKey(SL_APPLET_GCONF_PATH)), myContext(NULL), myWidget(NULL), myParent(NULL) { -SimpleLauncherApplet::SimpleLauncherApplet(const std::string& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myTransparent(GConfKey(base), "transparent", false), myIconSize(GConfKey(base), "icon_size", 48) { +SimpleLauncherApplet::SimpleLauncherApplet(const std::string& base) : myContext(NULL), myWidget(NULL), myParent(NULL), myValidItems(0), myTransparent(GConfKey(base), "transparent", false), myIconSize(GConfKey(base), "icon_size", 48) { } bool SimpleLauncherApplet::doInit(void *state_data, int *state_size) { @@ -205,7 +205,7 @@ void SimpleLauncherApplet::updateWidget() { GtkSizeGroup *group = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); - int button_no = 0; + myValidItems = 0; for (size_t i = 0 ; i < myItems.size() ; ++i) { LauncherItem *item = myItems[i]; @@ -230,19 +230,13 @@ void SimpleLauncherApplet::updateWidget() { gtk_box_pack_start(GTK_BOX(myWidget), GTK_WIDGET(button), false, false, 0); - ++button_no; + ++myValidItems; } } g_object_unref(G_OBJECT(group)); - int totalSize = myIconSize.value(); - - if (button_no == 0) { - gtk_widget_set_size_request(myWidget, totalSize, totalSize); - } else { - gtk_widget_set_size_request(myWidget, button_no*totalSize, totalSize); - } + gtk_widget_set_size_request(myWidget, getWidth(), getHeight()); gtk_widget_show_all(myWidget); } @@ -316,4 +310,23 @@ void SimpleLauncherApplet::runDialog() { // newItems.clear(); // TODO: do I really need it? } +int SimpleLauncherApplet::getWidth() const { + if (myValidItems) { + return myIconSize.value() * myValidItems; + } else { + return myIconSize.value(); + } +} + +int SimpleLauncherApplet::getHeight() const { + return myIconSize.value(); +} + +void SimpleLauncherApplet::getBackgroundColour(double& red, double& green, double& blue, double alpha) const { + // white :) + red = 1.0; green = 1.0; blue = 1.0; + + alpha = myTransparent.value() ? 0.0 : 1.0; +} + // vim:ts=2:sw=2:et diff --git a/simple-launcher.h b/simple-launcher.h index 566d27e..6455b2a 100644 --- a/simple-launcher.h +++ b/simple-launcher.h @@ -72,6 +72,7 @@ private: GtkWindow *myParent; LauncherItems myItems; + int myValidItems; GConfBooleanOption myTransparent; // bool myShowInfobanner; // FIXME: to implement -- 1.7.9.5