• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-341  評(píng)論-2670  文章-0  trackbacks-0
                GacUI添加了一個(gè)新的Demo。這個(gè)Demo用了幾個(gè)按鈕(之所以不用菜單是因?yàn)椴幌胱孌emo一下子包含太多新東西)來(lái)實(shí)現(xiàn)剪貼板操作、只讀控制和行跳轉(zhuǎn)等功能。在剪貼板里面的內(nèi)容是文字的時(shí)候,Paste按鈕會(huì)被Enable。這個(gè)過(guò)程是自動(dòng)的,也就是說(shuō),你在畫(huà)圖里面復(fù)制了一個(gè)圖片,這個(gè)按鈕也會(huì)變灰。Cut和Copy按鈕僅在文本框有文字被選中的時(shí)候可用,因此相應(yīng)了文本框的SelectionChanged來(lái)處理這件事情。如果文本框的內(nèi)容太多的話,{VS, Explorer} X {Debug, Release}這四種運(yùn)行方法里面,只有在Debug模式下掛了VS這種情況會(huì)感覺(jué)有點(diǎn)卡,其他的打開(kāi)方法都是很流暢的。先來(lái)看圖:



                代碼還是比較簡(jiǎn)單的。先用一個(gè)Table分成三行,前兩行讓行高縮短到最短,最后一行則利用了剩余空間的100%撐開(kāi)。前兩行里面的按鈕用Stack來(lái)對(duì)它們進(jìn)行排版。單行文本框沒(méi)有最小高度,所以依靠Stack和Table,它的高度會(huì)保持跟按鈕一致。代碼如下:

              1 #include "..\..\Public\Source\GacUIIncludes.h"
              2 #include <Windows.h>
              3 
              4 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
              5 {
              6     return SetupWindowsDirect2DRenderer();
              7 }
              8 
              9 class TextBoxEditorWindow : public GuiWindow
             10 {
             11 private:
             12     GuiButton*                        buttonCut;
             13     GuiButton*                        buttonCopy;
             14     GuiButton*                        buttonPaste;
             15     GuiButton*                        buttonSelectAll;
             16     GuiSelectableButton*            checkReadonly;
             17     GuiSinglelineTextBox*            textGoto;
             18     GuiButton*                        buttonGoto;
             19     GuiMultilineTextBox*            textDocument;
             20 
             21     void UpdateEditButtonState()
             22     {
             23         buttonCut->SetEnabled(textDocument->CanCut());
             24         buttonCopy->SetEnabled(textDocument->CanCopy());
             25         buttonPaste->SetEnabled(textDocument->CanPaste());
             26     }
             27 
             28     // ensure that the buttonGoto is enabled only when textGoto's content is a positive number
             29     void UpdateGotoButtonState()
             30     {
             31         buttonGoto->SetEnabled(utow(wtou(textGoto->GetText()))==textGoto->GetText() && wtou(textGoto->GetText())!=0);
             32     }
             33 
             34     // cut text box selection
             35     void buttonCut_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             36     {
             37         textDocument->Cut();
             38         textDocument->SetFocus();
             39     }
             40 
             41     // copy text box selection
             42     void buttonCopy_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             43     {
             44         textDocument->Copy();
             45         textDocument->SetFocus();
             46     }
             47 
             48     // paste text from clipboard
             49     void buttonPaste_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             50     {
             51         textDocument->Paste();
             52         textDocument->SetFocus();
             53     }
             54 
             55     // select all text
             56     void buttonSelectAll_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             57     {
             58         textDocument->SelectAll();
             59         textDocument->SetFocus();
             60     }
             61 
             62     // go to the specified line
             63     void buttonGoto_OnClicked(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             64     {
             65         int line=wtoi(textGoto->GetText())-1;
             66         textDocument->Select(TextPos(line, 0), TextPos(line, 0));
             67         textDocument->SetFocus();
             68     }
             69 
             70     // make the textbox readonly or not readonly
             71     void checkReadonly_OnSelectedChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             72     {
             73         textDocument->SetReadonly(checkReadonly->GetSelected());
             74         UpdateEditButtonState();
             75     }
             76 
             77     // when textGoto changed, disable buttonGoto if the text in the textGoto is failed to pass the validation
             78     void textGoto_TextChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             79     {
             80         UpdateGotoButtonState();
             81     }
             82 
             83     // update the edit buttons when selection changed
             84     void textDocument_SelectionChanged(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             85     {
             86         UpdateEditButtonState();
             87     }
             88     
             89     // update the edit buttons when clipboard changed changed
             90     void window_OnClipboardUpdated(GuiGraphicsComposition* sender, GuiEventArgs& arguments)
             91     {
             92         UpdateEditButtonState();
             93     }
             94 public:
             95     TextBoxEditorWindow()
             96         :GuiWindow(GetCurrentTheme()->CreateWindowStyle())
             97     {
             98         this->SetText(L"Controls.TextBox.Editor");
             99         this->GetContainerComposition()->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            100         this->ClipboardUpdated.AttachMethod(this&TextBoxEditorWindow::window_OnClipboardUpdated);
            101 
            102         GuiTableComposition* table=new GuiTableComposition;
            103         table->SetAlignmentToParent(Margin(0000));
            104         table->SetCellPadding(2);
            105         table->SetRowsAndColumns(31);
            106         table->SetRowOption(0, GuiCellOption::MinSizeOption());
            107         table->SetRowOption(1, GuiCellOption::MinSizeOption());
            108         table->SetRowOption(2, GuiCellOption::PercentageOption(1.0));
            109         table->SetColumnOption(0, GuiCellOption::PercentageOption(1.0));
            110         this->GetContainerComposition()->AddChild(table);
            111         
            112         {
            113             GuiCellComposition* cell=new GuiCellComposition;
            114             table->AddChild(cell);
            115             cell->SetSite(0011);
            116 
            117             GuiStackComposition* stack=new GuiStackComposition;
            118             stack->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            119             stack->SetPadding(2);
            120             stack->SetAlignmentToParent(Margin(0000));
            121             cell->AddChild(stack);
            122 
            123             {
            124                 GuiStackItemComposition* item=new GuiStackItemComposition;
            125                 stack->AddChild(item);
            126 
            127                 buttonCut=g::NewButton();
            128                 buttonCut->SetText(L"Cut");
            129                 buttonCut->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            130                 buttonCut->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonCut_OnClicked);
            131                 item->AddChild(buttonCut->GetBoundsComposition());
            132             }
            133             {
            134                 GuiStackItemComposition* item=new GuiStackItemComposition;
            135                 stack->AddChild(item);
            136 
            137                 buttonCopy=g::NewButton();
            138                 buttonCopy->SetText(L"Copy");
            139                 buttonCopy->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            140                 buttonCopy->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonCopy_OnClicked);
            141                 item->AddChild(buttonCopy->GetBoundsComposition());
            142             }
            143             {
            144                 GuiStackItemComposition* item=new GuiStackItemComposition;
            145                 stack->AddChild(item);
            146 
            147                 buttonPaste=g::NewButton();
            148                 buttonPaste->SetText(L"Paste");
            149                 buttonPaste->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            150                 buttonPaste->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonPaste_OnClicked);
            151                 item->AddChild(buttonPaste->GetBoundsComposition());
            152             }
            153             {
            154                 GuiStackItemComposition* item=new GuiStackItemComposition;
            155                 stack->AddChild(item);
            156 
            157                 buttonSelectAll=g::NewButton();
            158                 buttonSelectAll->SetText(L"Select All");
            159                 buttonSelectAll->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            160                 buttonSelectAll->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonSelectAll_OnClicked);
            161                 item->AddChild(buttonSelectAll->GetBoundsComposition());
            162             }
            163             {
            164                 GuiStackItemComposition* item=new GuiStackItemComposition;
            165                 stack->AddChild(item);
            166 
            167                 checkReadonly=g::NewCheckBox();
            168                 checkReadonly->SetText(L"Readonly");
            169                 checkReadonly->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            170                 checkReadonly->SelectedChanged.AttachMethod(this&TextBoxEditorWindow::checkReadonly_OnSelectedChanged);
            171                 item->AddChild(checkReadonly->GetBoundsComposition());
            172             }
            173         }
            174         {
            175             GuiCellComposition* cell=new GuiCellComposition;
            176             table->AddChild(cell);
            177             cell->SetSite(1011);
            178 
            179             GuiStackComposition* stack=new GuiStackComposition;
            180             stack->SetMinSizeLimitation(GuiGraphicsComposition::LimitToElementAndChildren);
            181             stack->SetPadding(2);
            182             stack->SetAlignmentToParent(Margin(0000));
            183             cell->AddChild(stack);
            184 
            185             {
            186                 GuiStackItemComposition* item=new GuiStackItemComposition;
            187                 stack->AddChild(item);
            188 
            189                 textGoto=g::NewTextBox();
            190                 textGoto->GetBoundsComposition()->SetBounds(Rect(Point(00), Size(1800)));
            191                 textGoto->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            192                 textGoto->TextChanged.AttachMethod(this&TextBoxEditorWindow::textGoto_TextChanged);
            193                 item->AddChild(textGoto->GetBoundsComposition());
            194             }
            195             {
            196                 GuiStackItemComposition* item=new GuiStackItemComposition;
            197                 stack->AddChild(item);
            198 
            199                 buttonGoto=g::NewButton();
            200                 buttonGoto->SetText(L"Go to this line");
            201                 buttonGoto->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            202                 buttonGoto->Clicked.AttachMethod(this&TextBoxEditorWindow::buttonGoto_OnClicked);
            203                 item->AddChild(buttonGoto->GetBoundsComposition());
            204             }
            205         }
            206         {
            207             GuiCellComposition* cell=new GuiCellComposition;
            208             table->AddChild(cell);
            209             cell->SetSite(2011);
            210 
            211             textDocument=g::NewMultilineTextBox();
            212             textDocument->GetBoundsComposition()->SetAlignmentToParent(Margin(0000));
            213             textDocument->SelectionChanged.AttachMethod(this&TextBoxEditorWindow::textDocument_SelectionChanged);
            214             cell->AddChild(textDocument->GetBoundsComposition());
            215         }
            216 
            217         // make some buttons enabled or disabled appropiately
            218         UpdateEditButtonState();
            219         UpdateGotoButtonState();
            220         // set the preferred minimum client size
            221         this->GetBoundsComposition()->SetPreferredMinSize(Size(640480));
            222         // call this to calculate the size immediately if any indirect content in the table changes
            223         // so that the window can calcaulte its correct size before calling the MoveToScreenCenter()
            224         this->ForceCalculateSizeImmediately();
            225         // move to the screen center
            226         this->MoveToScreenCenter();
            227     }
            228 
            229     ~TextBoxEditorWindow()
            230     {
            231     }
            232 };
            233 
            234 void GuiMain()
            235 {
            236     GuiWindow* window=new TextBoxEditorWindow();
            237     GetApplication()->Run(window);
            238     delete window;
            239 }

                GacUI將提供兩個(gè)文本框的Demo,這是第一個(gè)。GacUI的文本框從一開(kāi)始就具備了讓每一個(gè)字符的顏色可以不同的功能,下一個(gè)Demo將展示如何利用使用正則表達(dá)式構(gòu)建的詞法分析器(見(jiàn)這里這里),讓文本框在編輯的時(shí)候,跟所有的代碼編輯器一樣,可以根據(jù)情況把不同的字符串染成不同的顏色。
            posted on 2012-05-05 02:37 陳梓瀚(vczh) 閱讀(5337) 評(píng)論(5)  編輯 收藏 引用 所屬分類: GacUI

            評(píng)論:
            # re: GacUI Demo:文本框基本應(yīng)用 2012-05-05 08:24 | 空明流轉(zhuǎn)
            基本成型了。。。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:文本框基本應(yīng)用[未登錄](méi) 2012-05-06 02:10 | me
            你太厲害了!別太累哦!  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:文本框基本應(yīng)用 2012-05-06 05:28 | Zblc(邱震鈺)
            不容易瓦  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:文本框基本應(yīng)用 2012-05-07 00:14 | vczh
            公司發(fā)winphone7.5手機(jī)了滅哈哈。  回復(fù)  更多評(píng)論
              
            # re: GacUI Demo:文本框基本應(yīng)用[未登錄](méi) 2012-05-07 16:37 | me
            哇哇哇!!!  回復(fù)  更多評(píng)論
              
            国内精品久久久久影院网站| 久久国产精品77777| 无码国内精品久久人妻麻豆按摩| 99精品伊人久久久大香线蕉| 亚洲国产精品狼友中文久久久| 国产精品日韩欧美久久综合| 久久午夜免费视频| 成人国内精品久久久久影院| 日韩欧美亚洲综合久久影院Ds| 久久综合鬼色88久久精品综合自在自线噜噜| 国产亚洲精午夜久久久久久 | 国产精品久久久久影院色| 久久精品国产99国产精品澳门| 国内精品久久久久久不卡影院 | 精品久久人人爽天天玩人人妻| 亚洲精品乱码久久久久久中文字幕| 欧美牲交A欧牲交aⅴ久久| 久久久噜噜噜久久| 国产精品久久久久久福利漫画| 欧美久久一区二区三区| 97精品国产91久久久久久| 久久99久久99精品免视看动漫 | 国产精品美女久久久免费| 久久久噜噜噜www成人网| 亚洲欧美日韩精品久久亚洲区 | 久久精品国产亚洲αv忘忧草| 狠狠色丁香久久婷婷综| 久久久噜噜噜久久熟女AA片| 色欲综合久久躁天天躁蜜桃| 久久中文精品无码中文字幕| 国产精品99久久不卡| 国产精品久久99| 久久精品国产99久久无毒不卡| 亚洲精品tv久久久久| 久久天天婷婷五月俺也去| 欧美一级久久久久久久大片| 久久久久亚洲AV综合波多野结衣| 国产—久久香蕉国产线看观看| 成人资源影音先锋久久资源网| 亚洲va久久久噜噜噜久久天堂| 久久精品国产AV一区二区三区|