[Libreoffice-commits] .: Branch 'feature/layout' - sw/source
Ricardo Cruz
rpmcruz at kemper.freedesktop.org
Sat Dec 18 08:55:27 PST 2010
sw/source/ui/dialog/wordcountdialog.cxx | 122 ++++++++++++++------------------
sw/source/ui/inc/wordcountdialog.hxx | 4 +
2 files changed, 60 insertions(+), 66 deletions(-)
New commits:
commit c176394ce7e80cda3223603d9a441ad7d3f37f7b
Author: Ricardo Cruz <rpmcruz at alunos.dcc.fc.up.pt>
Date: Sat Dec 18 16:54:31 2010 +0000
Re-implemented Table in a different line. Tweaks here and there.
diff --git a/sw/source/ui/dialog/wordcountdialog.cxx b/sw/source/ui/dialog/wordcountdialog.cxx
index 5711a9b..06cf696 100644
--- a/sw/source/ui/dialog/wordcountdialog.cxx
+++ b/sw/source/ui/dialog/wordcountdialog.cxx
@@ -117,93 +117,48 @@ SwWordCountDialog::SwWordCountDialog (Window* parent) :
aDocCharacterExcludingSpacesFT->SetText (String::CreateFromAscii ("Characters excluding spaces:"));
aDocCharacterExcludingSpacesFI = new FixedInfo (this);
+ // FIXME: this shouldn't be necessary ....
+ aCurrentWordFI->SetText( String::CreateFromInt32(0 ));
+ aCurrentCharacterFI->SetText(String::CreateFromInt32(0 ));
+ aCurrentCharacterExcludingSpacesFI->SetText(String::CreateFromInt32(0 ));
+ aDocWordFI->SetText( String::CreateFromInt32(0 ));
+ aDocCharacterFI->SetText( String::CreateFromInt32(0 ));
+ aDocCharacterExcludingSpacesFI->SetText( String::CreateFromInt32(0 ));
+
// create layout
Notebook *notebook = new Notebook (this);
for (int page = 0; page < 2; page++) {
-#if 1 // 0: use a Table container, 1: use Box containers
- VBox *labels_box = new VBox (false, 6);
- VBox *counts_box = new VBox (false, 6);
-
- String str;
- switch (page) {
- case 0:
- str = String::CreateFromAscii ("Whole Document");
- labels_box->Pack (aDocWordFT, false, true);
- labels_box->Pack (aDocCharacterFT, false, true);
- labels_box->Pack (aDocCharacterExcludingSpacesFT, false, true);
-
- counts_box->Pack (aDocWordFI, false, true);
- counts_box->Pack (aDocCharacterFI, false, true);
- counts_box->Pack (aDocCharacterExcludingSpacesFI, false, true);
- break;
- case 1:
- str = String::CreateFromAscii ("Selected Text");
- labels_box->Pack (aCurrentWordFT, false, true);
- labels_box->Pack (aCurrentCharacterFT, false, true);
- labels_box->Pack (aCurrentCharacterExcludingSpacesFT, false, true);
-
- counts_box->Pack (aCurrentWordFI, false, true);
- counts_box->Pack (aCurrentCharacterFI, false, true);
- counts_box->Pack (aCurrentCharacterExcludingSpacesFI, false, true);
- break;
- }
-
- // FIXME: HBox may not be behaving correctly when expand=false for
- // counts_box.
- // Or it could be FixedInfo not returning a sufficient req-size. (Try
- // using another widgets in place of one of those.)
-
- Box *cols = new HBox (false, 6);
- cols->Pack (labels_box, true, true);
- cols->Pack (counts_box, true, true);
-
- notebook->AddPage (str, cols);
-#else
- // FIXME: Table isn't work that well:
- // * Children that use colExpand='false' aren't being shown:
- // contrast the two tabs (one of them sets false one of the columns.
- // * SetSpacing() seems to be ignored.
- // * Table methods use (row, col) order when (row, col) is
- // probably more intuitive given that (row, col) refer to
- // (Y, X) respectively.
- // * PackChild() use first-in first-served order, complemented with
- // col-span and row-span: we may want to follow gtk style here, and
- // instead have the user indicate (left-col, right-col, top-row,
- // bottom-row), which would provide some more flexible for the user
- // to insert a widget out of order in the Editor, or while running.
-
- Table *table = new Table (2);
+ table = new Table (2, 3);
table->SetSpacings (6, 6);
String str;
switch (page) {
case 0:
str = String::CreateFromAscii ("Whole Document");
- table->PackChild (aDocWordFT, 1, 1, false, true);
- table->PackChild (aDocWordFI, 1, 1, false, true);
+ table->Attach (aDocWordFT, 0, 1, 0, 1, true, false);
+ table->Attach (aDocWordFI, 1, 2, 0, 1, false, false);
- table->PackChild (aDocCharacterFT, 1, 1, false, true);
- table->PackChild (aDocCharacterFI, 1, 1, false, true);
+ table->Attach (aDocCharacterFT, 0, 1, 1, 2, false, false);
+ table->Attach (aDocCharacterFI, 1, 2, 1, 2, false, false);
- table->PackChild (aDocCharacterExcludingSpacesFT, 1, 1, false, true);
- table->PackChild (aDocCharacterExcludingSpacesFI, 1, 1, false, true);
+ table->Attach (aDocCharacterExcludingSpacesFT, 0, 1, 2, 3, false, false);
+ table->Attach (aDocCharacterExcludingSpacesFI, 1, 2, 2, 3, false, false);
break;
case 1:
str = String::CreateFromAscii ("Selected Text");
- table->PackChild (aCurrentWordFT, 1, 1, false, true);
- table->PackChild (aCurrentWordFI, 1, 1, false, false);
+ table->Attach (aCurrentWordFT, 0, 1, 0, 1, true, false);
+ table->Attach (aCurrentWordFI, 1, 2, 0, 1, false, false);
- table->PackChild (aCurrentCharacterFT, 1, 1, false, true);
- table->PackChild (aCurrentCharacterFI, 1, 1, false, false);
+ table->Attach (aCurrentCharacterFT, 0, 1, 1, 2, false, false);
+ table->Attach (aCurrentCharacterFI, 1, 2, 1, 2, false, false);
- table->PackChild (aCurrentCharacterExcludingSpacesFT, 1, 1, false, true);
- table->PackChild (aCurrentCharacterExcludingSpacesFI, 1, 1, false, false);
+ table->Attach (aCurrentCharacterExcludingSpacesFT, 0, 1, 2, 3, false, false);
+ table->Attach (aCurrentCharacterExcludingSpacesFI, 1, 2, 2, 3, false, false);
break;
}
notebook->AddPage (str, table);
-#endif
}
ButtonBox *bbox = new ButtonBox();
@@ -211,6 +166,7 @@ SwWordCountDialog::SwWordCountDialog (Window* parent) :
aOK = new OKButton (this);
PushButton *refreshButton = new PushButton (this);
refreshButton->SetText (String::CreateFromAscii ("Refresh"));
+ refreshButton->SetClickHdl (LINK (this, SwWordCountDialog, RefreshHdl));
bbox->Pack (aHelp, HELP_BUTTON);
bbox->Pack (aOK, OK_BUTTON);
@@ -241,6 +197,40 @@ void SwWordCountDialog::SetValues(const SwDocStat& rCurrent, const SwDocStat& r
aDocWordFI->SetText( String::CreateFromInt32(rDoc.nWord ));
aDocCharacterFI->SetText( String::CreateFromInt32(rDoc.nChar ));
aDocCharacterExcludingSpacesFI->SetText( String::CreateFromInt32(rDoc.nCharExcludingSpaces ));
+
+ // It won't be necessary to explicitely request a new size once
+ // we build such code into the widgets.
+ Layout::QueueResize (table);
+
+#if 0
+ // At the moment, we cannot call Layout::QueueResize() on the widgets
+ // because their layout parent and window parent differ, so Table
+ // won't report size change.
+
+ Layout::QueueResize (aCurrentWordFI);
+ Layout::QueueResize (aCurrentCharacterFI);
+ Layout::QueueResize (aCurrentCharacterExcludingSpacesFI);
+ Layout::QueueResize (aDocWordFI);
+ Layout::QueueResize (aDocCharacterFI);
+ Layout::QueueResize (aDocCharacterExcludingSpacesFI);
+#endif
+}
+
+IMPL_LINK( SwWordCountDialog, RefreshHdl, PushButton *, EMPTYARG )
+{
+ SwDocStat cur, whole;
+ int charsNb = (rand() % 4) + 1;
+ int base = pow (10, charsNb);
+ cur.nWord = rand() % base;
+ cur.nChar = rand() % base;
+ cur.nCharExcludingSpaces = rand() % base;
+
+ whole.nWord = rand() % base;
+ whole.nChar = rand() % base;
+ whole.nCharExcludingSpaces = rand() % base;
+
+ SetValues (cur, whole);
+ return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/inc/wordcountdialog.hxx b/sw/source/ui/inc/wordcountdialog.hxx
index f7715b3..93419d4 100644
--- a/sw/source/ui/inc/wordcountdialog.hxx
+++ b/sw/source/ui/inc/wordcountdialog.hxx
@@ -34,6 +34,7 @@
#include <layout/layout.hxx>
#include <layout/layout-pre.hxx>
struct SwDocStat;
+struct Table;
class SwWordCountDialog : public LDialog
{
FixedLine *aCurrentFL;
@@ -57,6 +58,9 @@ class SwWordCountDialog : public LDialog
OKButton *aOK;
HelpButton *aHelp;
+ Table *table;
+ DECL_LINK( RefreshHdl, PushButton * );
+
public:
SwWordCountDialog(Window* pParent);
~SwWordCountDialog();
More information about the Libreoffice-commits
mailing list