~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to src/mgui/editor/toolbar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
Import upstream version 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "toolbar.h"
25
25
#include "actions.h"
 
26
#include "fe-select.h"
26
27
 
27
28
#include <mgui/win_utils.h>
28
29
#include <mgui/img-factory.h>
32
33
#include <mgui/sdk/gnc-gtk-utils.h>
33
34
#include <mgui/sdk/entry.h>
34
35
#include <mgui/sdk/packing.h>
 
36
#include <mgui/sdk/widget.h>
35
37
 
36
38
#include <mgui/render/menu.h>
37
39
#include <mgui/render/editor.h>
40
42
 
41
43
#include <mbase/project/theme.h>
42
44
#include <mlib/sdk/logger.h>
 
45
#include <mlib/range/enumerate.h>
43
46
 
44
47
namespace Editor
45
48
{
46
49
 
47
 
void ForAllSelected(FTOFunctor fto_fnr, TextObjFunctor txt_fnr, MenuRegion& mn_rgn, const int_array& sel_arr)
 
50
void ForAllSelected(FTOFunctor fto_fnr, TextObjFunctor txt_fnr)
48
51
{
 
52
    MenuRegion& mn_rgn = CurMenuRegion();
 
53
 
49
54
    bool fto_continue = fto_fnr;
50
55
    bool txt_continue = txt_fnr;
51
 
    Comp::ListObj::ArrType& lst = mn_rgn.List();
52
 
    for( int i=0; (fto_continue || txt_continue) && i<(int)sel_arr.size(); ++i )
 
56
    //Comp::ListObj::ArrType& lst = mn_rgn.List();
 
57
    //for( int i=0; (fto_continue || txt_continue) && i<(int)sel_arr.size(); ++i )
 
58
    boost_foreach( Comp::MediaObj* obj, SelectedMediaObjs() )
53
59
    {
54
 
        Comp::Object* obj = lst[sel_arr[i]];
 
60
        if( !(fto_continue || txt_continue) )
 
61
            break;
55
62
 
56
63
        if( fto_continue )
57
64
            if( FrameThemeObj* fto_obj = dynamic_cast<FrameThemeObj*>(obj) )
69
76
    }
70
77
}
71
78
 
72
 
void ForAllSelectedFTO(FTOFunctor fnr, MenuRegion& mn_rgn, const int_array& sel_arr)
 
79
void ForAllSelectedFTO(FTOFunctor fnr)
73
80
{
74
 
    ForAllSelected(fnr, TextObjFunctor(), mn_rgn, sel_arr);
 
81
    ForAllSelected(fnr, TextObjFunctor());
75
82
}
76
83
 
77
84
 
161
168
        //TooltipFactory().set_tip(*combo.get_child(), "Frame Type");
162
169
        Str::List lst;
163
170
        Project::GetThemeList(lst);
164
 
        //fill_clr = GetStyleColorBg(Gtk::STATE_NORMAL, combo).ToUint();
165
 
        for( Str::List::iterator itr = lst.begin(), end = lst.end(); itr != end; ++itr )
 
171
        boost_foreach( fe::index_value<std::string&> iv, lst | fe::enumerated() )
166
172
        {
167
173
            Gtk::TreeRow row = *f_store->append();
168
 
            const std::string& theme_str = *itr;
 
174
            const std::string& theme_str = iv.value();
169
175
            // *
170
176
            row[pix_cln] = RenderToolbarFrame(theme_str, fill_clr);
171
177
            row[str_cln] = theme_str;
172
178
            if( theme_str == "rect" )
173
 
                combo.set_active(itr-lst.begin());
 
179
                combo.set_active(iv.index());
174
180
        }
175
181
        // * внешний вид
176
182
        combo.pack_start(pix_cln, false);
203
209
    fnt_desc.set_weight(bldBtn.get_active() ? Pango::WEIGHT_BOLD : Pango::WEIGHT_NORMAL);
204
210
    fnt_desc.set_style(itaBtn.get_active() ? Pango::STYLE_ITALIC : Pango::STYLE_NORMAL);
205
211
 
206
 
    RGBA::Pixel pxl(clrBtn.get_color());
207
 
    pxl.alpha = RGBA::FromGdkComponent(clrBtn.get_alpha());
208
 
    return TextStyle(fnt_desc, undBtn.get_active(), pxl);
 
212
    return TextStyle(fnt_desc, undBtn.get_active(), GetColor(clrBtn));
209
213
}
210
214
 
211
 
std::string GetActiveTheme(Gtk::ComboBox& combo)
 
215
std::string GetActiveTheme()
212
216
{
 
217
    Gtk::ComboBox& combo = MenuToolbar().frame_combo;
213
218
    Gtk::TreeIter itr = combo.get_active();
214
219
    return itr ? itr->get_value(FrameTypeColumn) : std::string() ;
215
220
}
243
248
 
244
249
    typedef Glib::ArrayHandle<RefPtr<Pango::FontFamily> > FFArray;
245
250
    FFArray arr = context->list_families();
246
 
    for( FFArray::iterator itr = arr.begin(), end = arr.end(); itr != end; ++itr )
247
 
        lst->push_back((*itr)->get_name());
 
251
    boost_foreach( RefPtr<Pango::FontFamily> ff, arr )
 
252
        lst->push_back(ff->get_name());
248
253
 
249
254
    std::sort(lst->begin(), lst->end());
250
255
    return lst;
356
361
{
357
362
    MenuRegion& rgn = editor.CurMenuRegion();
358
363
 
359
 
    Project::AddFTOItem(rgn, Editor::GetActiveTheme(editor.Toolbar().frame_combo), lct, mi);
 
364
    FrameThemeObj* fto = Project::NewFTO(Editor::GetActiveTheme(), lct);
 
365
    fto->MediaItem().SetLink(mi);
 
366
    Project::AddMenuItem(rgn, fto);
 
367
 
360
368
    RenderForRegion(editor, Planed::AbsToRel(rgn.Transition(), lct));
361
369
}
362
370
 
373
381
    AddFTOItem(editor, lct, mi);
374
382
}
375
383
 
376
 
static void AddObjectClicked(MEditorArea& editor)
 
384
static void AddObjectClicked()
377
385
{
 
386
    MEditorArea& editor = MenuEditor();
378
387
    if( Project::Menu mn = editor.CurMenu() )
379
388
    {
380
389
        // * находим положение
387
396
    }
388
397
}
389
398
 
390
 
static bool ReframeFTO(RectListRgn& r_lst, FrameThemeObj* obj, 
391
 
                       const std::string& theme, MenuRegion& mn_rgn)
 
399
static bool ReframeFTO(RectListRgn& r_lst, FrameThemeObj* obj, MenuRegion& mn_rgn)
392
400
{
 
401
    const std::string& theme = Editor::GetActiveTheme();
393
402
    if( theme != obj->Theme() )
394
403
    {
395
404
        obj->GetData<FTOInterPixData>().ClearPix();
399
408
    return true;
400
409
}
401
410
 
402
 
static void FrameTypeChanged(MEditorArea& editor)
 
411
static void FrameTypeChanged()
403
412
{
404
 
    using namespace boost;
405
 
    MenuRegion& mn_rgn = editor.CurMenuRegion();
406
413
    RectListRgn r_lst;
407
 
    ForAllSelectedFTO( lambda::bind(&ReframeFTO, boost::ref(r_lst), lambda::_1, 
408
 
                                    Editor::GetActiveTheme(editor.Toolbar().frame_combo), lambda::_2),
409
 
                       mn_rgn, editor.SelArr() );
410
 
    RenderForRegion(editor, r_lst);
 
414
    ForAllSelectedFTO( bb::bind(&ReframeFTO, boost::ref(r_lst), _1, _2) );
 
415
    RenderForRegion(MenuEditor(), r_lst);
411
416
}
412
417
 
413
418
static void EntryChanged(Gtk::Entry& ent, bool is_activate, ActionFunctor fnr)
419
424
// вызов действия при изменении в поле ввода (улучшенный "activate")
420
425
void ConnectOnActivate(Gtk::Entry& ent, ActionFunctor fnr)
421
426
{
422
 
    ent.signal_activate().connect( boost::lambda::bind(&EntryChanged, boost::ref(ent), true, fnr) );
423
 
    ent.signal_changed().connect(  boost::lambda::bind(&EntryChanged, boost::ref(ent), false, fnr) );
 
427
    ent.signal_activate().connect( bb::bind(&EntryChanged, boost::ref(ent), true,  fnr) );
 
428
    ent.signal_changed().connect(  bb::bind(&EntryChanged, boost::ref(ent), false, fnr) );
424
429
}
425
430
 
426
431
static void FontNameChanged(MEditorArea& editor, bool only_clr)
428
433
    SetSelObjectsTStyle(editor, editor.Toolbar().GetFontDesc(), only_clr);
429
434
}
430
435
 
431
 
static void OnToolbarControlled(MEditorArea& editor, ActionFunctor fnr)
432
 
{
433
 
//     if( Gtk::Widget* wdg = GetFocusWidget(editor) )
434
 
//         PrintWidgetPath(*wdg);
435
 
//     else
436
 
//         io::cout << "Focus not on the window?" << io::endl;
437
 
 
438
 
    if( !editor.has_focus() && editor.CurMenu() )
439
 
    {
440
 
        fnr();
441
 
        // *
442
 
        GrabFocus(editor);
443
 
    }
444
 
}
445
 
 
446
436
static void SetupStyleBtn(Gtk::ToggleButton& btn, Gtk::Toolbar& tbar,
447
437
                          const char* tooltip, const ActionFunctor& fnr,
448
438
                          Gtk::BuiltinStockID stock_id)
462
452
    btn.signal_toggled().connect(fnr);
463
453
}
464
454
 
 
455
// хочется отрабатывать изменения в управляющих элементах только когда
 
456
// фокус не на редакторе (т.е. когда не сам редактор изменился)
 
457
static void OnToolbarControlled(const ActionFunctor& fnr)
 
458
{
 
459
    MEditorArea& editor = MenuEditor();
 
460
//     if( Gtk::Widget* wdg = GetFocusWidget(editor) )
 
461
//         PrintWidgetPath(*wdg);
 
462
//     else
 
463
//         io::cout << "Focus not on the window?" << io::endl;
 
464
 
 
465
    if( !editor.has_focus() && editor.CurMenu() )
 
466
    {
 
467
        fnr();
 
468
        // *
 
469
        GrabFocus(editor);
 
470
    }
 
471
}
 
472
 
 
473
static ActionFunctor MakeToolbarFunctor(const ActionFunctor& fnr)
 
474
{
 
475
    return bb::bind(&OnToolbarControlled, fnr);
 
476
}
 
477
 
465
478
Gtk::Toolbar& PackToolbar(MEditorArea& editor, Gtk::VBox& lct_box)
466
479
{
467
480
    Editor::Toolbar& edt_tbar = editor.Toolbar();
476
489
    tbar.append(edt_tbar.txtTool);
477
490
    AppendTSeparator(tbar);
478
491
 
479
 
    // хочется отрабатывать изменения в управляющих элементах только когда
480
 
    // фокус не на редакторе (т.е. когда не сам редактор изменился)
481
 
    typedef boost::function<void(ActionFunctor)> ActionActionFunctor;
482
 
    ActionActionFunctor otc = bl::bind(&OnToolbarControlled, boost::ref(editor), bl::_1);
483
 
 
484
492
    // * выбор темы объекта
485
493
    {
486
494
        Gtk::ComboBox& combo = edt_tbar.frame_combo;
487
495
        AppendToToolbar(tbar, combo);
488
 
        combo.signal_changed().connect(
489
 
            bl::bind(otc, ActionFunctor(bl::bind(&FrameTypeChanged, boost::ref(editor)))));
 
496
        combo.signal_changed().connect(MakeToolbarFunctor(&FrameTypeChanged));
490
497
 
491
498
        // * кнопка
492
499
        Gtk::ToolButton& add_btn = NewManaged<Gtk::ToolButton>(Gtk::StockID(Gtk::Stock::ADD));
493
500
        add_btn.set_tooltip(TooltipFactory(), _("Add Item"));
494
501
        tbar.append(add_btn);
495
 
        add_btn.signal_clicked().connect( bl::bind(&AddObjectClicked, boost::ref(editor)) );
 
502
        add_btn.signal_clicked().connect(&AddObjectClicked);
496
503
    }
497
504
    AppendTSeparator(tbar);
498
505
 
499
506
    // * управление шрифтами
500
 
    ActionFunctor on_font_change = bl::bind(otc, ActionFunctor(bl::bind(&FontNameChanged, boost::ref(editor), false)));
 
507
    ActionFunctor on_font_change = MakeToolbarFunctor(bb::bind(&FontNameChanged, boost::ref(editor), false));
501
508
    {
502
509
        std::string def_font = tbar.get_style()->get_font().get_family().raw();
503
510
        // * семейства
504
511
        Gtk::ComboBoxEntryText& fonts_ent = edt_tbar.fontFmlEnt;
505
512
        Str::PList lst = GetFamiliesList(tbar.get_toplevel()->get_pango_context());
506
 
        for( Str::List::iterator itr = lst->begin(), end = lst->end(); itr != end; ++itr )
 
513
        boost_foreach( fe::index_value<std::string&> ff, *lst | fe::enumerated() )
507
514
        {
508
 
            fonts_ent.append_text(*itr);
509
 
            if( *itr == def_font )
510
 
                fonts_ent.set_active(itr-lst->begin());
 
515
            fonts_ent.append_text(ff.value());
 
516
            if( ff.value() == def_font )
 
517
                fonts_ent.set_active(ff.index());
511
518
        }
512
519
        AppendToToolbarWithAC(tbar, fonts_ent, true);
513
520
        {
539
546
 
540
547
        // * кнопка цвета текста
541
548
        Gtk::ColorButton& clr_btn = edt_tbar.clrBtn;
542
 
        clr_btn.set_use_alpha();
 
549
        ConfigureRGBAButton(clr_btn, RGBA::Pixel(GOLD_CLR));
543
550
        clr_btn.set_relief(Gtk::RELIEF_NONE);
544
 
        clr_btn.set_color(RGBA::PixelToColor(GOLD_CLR));
545
 
        clr_btn.set_alpha(0xffff);
546
551
 
547
552
        clr_btn.set_title(_("Pick a Color for Text"));
548
553
        clr_btn.set_focus_on_click(false);
549
554
        SetTip(clr_btn, _("Text Color"));
550
555
 
551
 
        clr_btn.signal_color_set().connect(bl::bind(&FontNameChanged, boost::ref(editor), true));
 
556
        clr_btn.signal_color_set().connect(MakeToolbarFunctor(bb::bind(&FontNameChanged, boost::ref(editor), true)));
552
557
        AppendToToolbar(tbar, clr_btn);
553
558
 
554
559
    }
559
564
    frm_btn.set_relief(Gtk::RELIEF_NONE);
560
565
    frm_btn.add(GetFactoryGtkImage("copy-n-paste/lpetool_show_bbox.png"));
561
566
    SetTip(frm_btn, _("Show Safe Area"));
562
 
    // обвязка otc здесь используется для проверки, что в редакторе есть меню (и не валится при его отстутствии)
563
 
    frm_btn.signal_toggled().connect(bl::bind(otc, ActionFunctor(bl::bind(&ToggleSafeArea, boost::ref(editor)))));
 
567
    // обвязка здесь используется для проверки, что в редакторе есть меню (и не валится при его отстутствии)
 
568
    frm_btn.signal_toggled().connect(MakeToolbarFunctor(&ToggleSafeArea));
564
569
 
565
570
    return tbar;
566
571
}